Re: Newbie struggling with form validation (1st question) -
08-04-2004
, 06:05 PM
An important thing that happens is html forms by default will auto
submit when hitting enter in a text field (under certain conditions).
To do proper javascript validations, put the following line in the
form onsubmit='return false'. This will turn off all submits that are
triggered by keyboard enters or submit button presses.
To do a proper submit, create a button: <input name='btSubmit'
type=button value='Submit' onclick='btSubmit_click(event)'>.
Add the following code:
btSubmit_click(e){
if(!yourValidationCode()){return}
document.forms["yourformname"].submit()
}
This should eliminate your problems and eliminates the need for submit
buttons. If you want to still trap enters, drop onclick listeners on
all text boxes and check event.keyCode.
JsD |