Page 1 of 1

help me to validate instantly

Posted: Mon Sep 21, 2009 10:55 pm
by om.bitsian
Hello friends
suppose i have 3 fields in my form...
<form action="" id="form2" method="post" name="form1" class="style1">
<label>1. Name</label>
<input type="text" name="name" size="30" maxlength="30" >
<label>2. Basic Pay</label>
<input type="text" name="basic" >
<label>3. Date of Birth</label>
<input name="BIRTH_YEAR" type="text" size="4" maxlength="4" >
/
<input name="BIRTH_MONTH" type="text" size="2" maxlength="2" >
/
<input name="BIRTH_DATE" type="text" size="2" maxlength="2" >


help me to write a javascript in which when i enter name:12445 (Error) and as soon as i jump to the next entry(Basic pay) it should display the error that "please enter only character value."
this will go on untill i enter all correct values

Re: help me to validate instantly

Posted: Tue Sep 22, 2009 11:57 am
by kaszu
Bind to inputs 'blur' event (it's fired when input looses focus) and check its value.
If it doesn't match (you will need to use regular expression to check that) your requirements, then show error message, which can be done using

Code: Select all

element.style.display='block';
All needed can be found in tutorials on http://www.w3schools.com/JS/default.asp.