Originally posted by Chhaya Dhanani:
HI ALL,
i wannt to do a few validations on the value of input fields.
these input fields are in jsp page and the nameis generated dynamcally inside a forloop.
for eg:
<input type ="text name="text1">
<input type ="text name="text2">
where the names "text1" and "text2" are generated dynamically..
the number of input fields also varies.
what i want to validate is the value of these input fields shud not be the same..
i.e. no two input fields shud have the same valeu.
how doi go abt doing this when i do not know the number of text fields and how doi compare eachvalue with all the other values..???
PLEASE REPLY SOON
THIS IS AN SOS
thanx to all in advance..
Chhaya
Warning this is off the top of my head,I have not verified/run the code but it might be of some help:
function getArrayOfValues(){
var a = new Array()
var d = document.formanme
var x = 1;//offset for each field
while( d["text"+x] ){
a[a.length] = d["text"+x].value;
a[a.length-1].id = x;//id of the field
}
return a;
}
function checkTextValues(){
var x;
var a = getArrayOfValues();
a.sort();
for( x = 0; x < a.length-1; x++ ){
if( a[x] == a[x+1] ){
alert( "duplicate values for " + a[x] );
document.formname["text"+a[x].id].focus()
}
return "text" + a[x].id ;
}
}
[ April 11, 2002: Message edited by: Charlie Sturman ]
[ April 11, 2002: Message edited by: Charlie Sturman ]