1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Form onSubmit alert()

Discussion in 'JavaScript' started by svoltmer, Aug 12, 2008.

  1. #1
    have a form that onSubmit processes using "formMail". I would like to also have it display an "alert('Form Submitted - Thank You") onSubmit as well. I have tried all kinds of methods, but nothing is working. Any suggestions? Thanks!

    Link: http://www.crosst.org/saved.html
     
    svoltmer, Aug 12, 2008 IP
  2. fireflyproject

    fireflyproject Active Member

    Messages:
    969
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    70
    #2
    If you think linearly, you might catch what I think the problem is.

    When you submit the form, it runs a validate function. What happens at the end of this function? Does it return true? If so, you are then giving the go ahead to send the form. You want your alert to happen before all this is done. So maybe add your alert() in at the very top of your validate function.
     
    fireflyproject, Aug 12, 2008 IP
  3. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Or use AJAX.
    The problem with showing a validation message like this is that it's not genuine because you show it before you know whether or not the operation was successful. This may or may not be a problem. It depends on the site.
     
    LogicFlux, Aug 12, 2008 IP
  4. yleiko

    yleiko Peon

    Messages:
    74
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <script alnguage="javascript">
    function sayHello()
    {
    alert("Hello World");
    return true;
    }
    </script>
    
    Code (markup):
    
    <form onSubmit="return sayHello()">
    some form objects
    <input type="submit" value="Submit Form">
    </form>
    
    HTML:
    this may give you some idea
     
    yleiko, Aug 12, 2008 IP
  5. svoltmer

    svoltmer Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I still can't get it to work. I have a limitation, I am using the "formMail" script on a shared web host. Something about the formmail.pl validating doesn't seem to allow me to add an additional "onSubmit" to the form. See what I have tried. Any new suggestions would be appreciated.

    <script alnguage="javascript">
    function formSubmit()
    {
    alert("Form Submitted - Thank You");
    return true;
    }
    </script>

    <form class="salvation" name="Salvation" method="POST" action="/cgi-sys/formmail.pl" onSubmit="formSubmit() && return validate(this)">


    I HAVE TRIED THIS TOO:

    <form class="salvation" name="Salvation" method="POST" action="/cgi-sys/formmail.pl" onSubmit="return validate(this); return formSubmit();">
     
    svoltmer, Aug 13, 2008 IP
  6. FlakDevelopment

    FlakDevelopment Banned

    Messages:
    164
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    add an alert at the bottom of the formSubmit thing.
     
    FlakDevelopment, Aug 13, 2008 IP
  7. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <form class="salvation" name="Salvation" method="POST" action="/cgi-sys/formmail.pl" onSubmit="return formSubmit();">

    As yleiko suggested.
     
    LogicFlux, Aug 13, 2008 IP
  8. svoltmer

    svoltmer Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I still need the "formmail.pl" to validate the form data. If i just use the alert() in the function then the data does not go through the formmail.pl script. Help?
     
    svoltmer, Aug 13, 2008 IP
  9. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #9
    Add the alert() call in the onload of the body of the resulting page generated by formmail.pl. You need to modify formmail.pl to do that.
     
    rkquest, Aug 13, 2008 IP
  10. svoltmer

    svoltmer Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I don't have access to the "formmail.pl" it is in a secure directory on the hosing company's server.
    I was able however to put a onClick event on the submit input to run the alert function. It's working fine now. Thanks for your input.
     
    svoltmer, Aug 14, 2008 IP