HI i have many fields in form....i want to check if anyfield is null so i want to do alert mesege also want to change the colour of text field....i have written a code but no error but not working anything...my code is for java scritpt
function validateForm(Qform){
var i=0,Q= Qform.elements,L=Q.length;
for (var a = 0; a < L; a++){
var field = Q[a];
if(field.value===''){
field.style.backgroundColor='red';
++i;
}
else field.style.backgroundColor='';
}
if(i){
alert('You must provide values for all the fields');
return false;
}
return true;
}
and my form code is
<form method="post" action="" enctype="" name="Qform" onSubmit="validateForm();">
<div class="centerform" >
<div id="divbox">
<label id="label">Name : </label>
<input id="input" type="text" name="txtPGrade" onBlur="validate(this.form.txtPGrade.value,'txtPGrade');"/>
<label id="CName">Invalid Data</label>
</div>
<strong>Assign New Currency</strong>
<div id="divbox">
<label id="label" >Currency : </label>
<select id="input"></select>
</div>
<div id="divbox">
<label id="label" >Minimum Sallary : </label>
<input id="input" type="text" name="txtMinSal" onBlur="validate(this.form.txtMinSal.value,'txtMinSal');"/>
<label id="MinSal">Invalid Sallary</label>
</div>
<div id="divbox">
<label id="label" >Maximum Sallary : </label>
<input id="input" type="text" name="txtMaxSal" onBlur="validate(this.form.txtMaxSal.value,'txtMaxSal');"/>
<label id="MaxSal">Invalid Sallary</label>
</div>
<div id="divbox">
<label id="label" >Step Increase : </label>
<input id="input" type="text" name="txtStepIncrease" />
</div>
<hr>
<input class="button" type="submit" name="btnsubmit" value="Submit" style="margin-left:150px;">
<input class="button" type="reset" name="btnreset" value="Reset" style="margin-top:-150px; ">
</div>
</form>
waiting for solution...
Regards..
Farhad Idrees