HighDots Forums  

Re: Newbie struggling with form validation (1st question)

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Newbie struggling with form validation (1st question) in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Java script Dude
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.