Link to home
Start Free TrialLog in
Avatar of varvoura
varvoura

asked on

Javascript form validation

Hi all,

I have a small javascript function which I have placed in the JSHeader to validate one of the form field, then I am calling this from the onsubmit event.
This works perfectly fine and i know that I can add dozens of fields to validate on the same way and it will do this with no problems. However, I was looking for a way that i can group all these validation at the end of the function, the display all that fail validation in one box on submit as oppose to 10 alerts for 10 fields and take the focus back to the first field that fail the validation.

SCRIPT

function validRequired()
{
if (document.forms[0].productno.value == "")
{
alert('Please enter a value in the hose serial no field.');
document.forms[0].productno.focus();
return false;

}
}

onsubmit return validRequired()
 
This is a notes client that i am trying this valiation on.

Thanks
Varvoura
ASKER CERTIFIED SOLUTION
Avatar of mshogren
mshogren

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of varvoura
varvoura

ASKER

Thank you.

I modified your example to take into account all fields that i need to validate on and I got it to set the focus in the exact field that's missing. eg. If the first field that i am validating on passes validation & the second doesn't then the focus is set to the 2nd field.

Much appreciated help and the points are yours.