onsubmit" handler is inserted inside the
and not inside any one element, unlike "
onblur." For example:
name="george" onsubmit="what_ever"> Lets do an example:
Enter Your name (*required) If you leave the required sections blank, as you click submit, you will be forced to come back and fill this box in.
Some every important things here:
document.example2.naming.value=="".What is the quotation in red? That is used to indicate an empty value- something that contains nothing. It is important that you distinguish between "" and " " The later means "1 empty space", as opposed to "empty value". The later is a char- namely, a space.
- What is "
return true", "
<a href="http://www.cssdrive.com" onclick="return false">Click here, it won't work!</a>
Click here, it won't work!
returning false, we prohibit the action from completing!
- Now, a confusing point may be-
onsubmit="return validate()". Why
return validate()? Wouldn't that be like a double return? No. Function validate only returns "true/false". You need "return true/fast" to actually manipulate whether a form submits or not. That's why we have to
return validate(), as opposed to just
Click here for a complete list of properties and methods of the Form object.