Question

I have a very basic form at http://www.happyholidaylites.com/contact.html and it is working great. When you submit the form, the user is brought to the index.html with no message that the form has been sent. I am looking to initiate an alert that says, "your form has been submitted" with an x button. My code looks like this:

      <form method="post" id="myForm" action="dynaform.php">

      <input type='hidden' name='rec_mailto' value='JBIRD1111@gmail.com'>
      <input type='hidden' name='rec_subject' value='New Contact Form'>
      <input type='hidden' name='rec_thanks' value='index.html'>

so on and so forth.....

The last line is what is telling the form what to do after the submit button is pressed, but I dont want it to point the browser to the index, rather I want a javascript popup with a success message. Any ideas?

Was it helpful?

Solution

Why not a simple onSubmit?

<form method="post" id="myForm" action="dynaform.php" onSubmit="alert('Thank you for your feedback.');" >

OTHER TIPS

To be honest you are better re-directing to another page in order to avoid the user re-submitting the page on a refresh. Have a look at Post/Redirect/Get Pattern.

Popups can be extremely annoying on websites. You should create a page called "thank-you.html" that you can re-direct the user to on successful submission which has access to the site navigation options or even just do a re-direct back to the form page after a few seconds.

Instead of redirecting to index.html, redirect to thanks.html; your users will thank you because everybody hates popups!

Sounds like your PHP script handles the form submission by processing the input and redirecting the browser to the value in the rec_thanks field.

You can add something like onsubmit="YourJavaScriptFunction()" to the form tag to add client-side behavior prior to actually submitting the form. Within that function you can perform validation, use alert('Thank You!'), etc..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top