Forum Moderators: open

Message Too Old, No Replies

prevent form submission until field is correct?

         

partha

4:05 am on Jul 26, 2005 (gmt 0)

10+ Year Member



I just want my users to be required to enter a valid email address before the form is submitted.

The function to validate an email address is easy and I know about onSubmit="" to make that function run before the form is submitted. But it just pops up an alert saying to enter a valid email address and then continues to submit the form!

How do I CANCEL the form submission if the email address entered is INVALID so the user can then enter a valid one?

Dijkgraaf

4:47 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Usually you would have something like
<form name="test" onsubmit="return validate();">
and your validate function would return true if everything is OK, but false if something was wrong. Note the return in front of the function in the onsubmit :-)

rocknbil

6:28 pm on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or just add onSubmit="return false;" to the form action tag.