Newbie struggling with form validation (1st question)

  • Thread starter François de Dardel
  • Start date
F

François de Dardel

I want to validate each field as it is filled. I also want to validate
the whole form beform submitting, checking for some "required" fields
to be filled before submit.

I managed both, and that works OK separately. The fields have following tags:
<TD><INPUT TABINDEX="25" TYPE="text" NAME="pH" SIZE=10 VALUE=7.5
ONBLUR="ValidateNumber(this, 'pH value must be between 5 and
9',5,9,7.4);"></TD>

However, when the error message appears and I press enter, the entire
form validation is triggered, which I don't want at this stage, but
only when pressing the "submit form" button at the bottom of the form.
Is there a way to achieve this ?

The whole thing is posted at:
http://mapage.noos.fr/dardelf4/tests/ADI_input.html

Thanks for any help or suggestions

--
François de Dardel
http:/mapage.noos.fr/dardelf/
Faber est suae quisque fortunae
Enlever le quatorze pour m'écrire
Remove fourteen in the address to send mail
 
J

Java script Dude

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top