help me to validate instantly

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
om.bitsian
Forum Commoner
Posts: 36
Joined: Wed Sep 09, 2009 4:13 am

help me to validate instantly

Post 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
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: help me to validate instantly

Post 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.
Post Reply