Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSubmit I would like to goto action page if true, reload page if fals

Status
Not open for further replies.

Sharla

Programmer
Oct 12, 2000
2
US
I have written a very simple form which asks for an email address. Upon submission I perform a javascript function which does some high level validation. If the validation is a success, I would like it to go to the action page. But if the validation was not successful, I would like the page to reload with an added error graphic.

Right now, it goes to the action page if successful. If not successful I just use an alert box with an error message. I am now being asked to add the error graphic. [sig][/sig]
 
This is an easy one!

Make the form's action page the same page (email address page), and then on loading the page, check if the form information is coming in, and if it's valid, move the user to the real action page, and otherwise give them an error.



Happy coding! [sig][/sig]
 
Another way to do it that works well is to have your validation function return a boolean value, true if it is a valid address, false if not. Place a call to that function in the onSubmit event handler of your form tag. It will submit as usual if the value returned is true, otherwise the user sits right where they were.
Example
<form action=&quot;Insert.htm&quot; method=&quot;post&quot; onSubmit=&quot;validateEmail()&quot;>
blah....blah....blah....
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top