roger_v
08-24-2009, 02:25 PM
Hello All,
I have a form that has several textboxes with identical names. I figured out a way to validate them by going row by row in the DOM. The problem is that I have a checkbox associated with each row and I need to validate only those rows that are checked and ignore the ones that aren't. Any ideas on how this might be accomplished? thanks,
Here is my validating procedure:
function isValid(){
var isDecimal_re = /^\d+(\.\d+)+$/; //to check for decimal input
var texts=document.getElementsByTagName("input");
columns=4;
for (i=0; i<texts.length; i++)
{
if (texts[i].type=="text")
{
if (!isDecimal_re.test(texts[i].value))
{
columnId=(i%columns)+1;
rowId=Math.ceil(i/columns)+1;
switch(columnId)
{
case 1:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
case 2:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
case 3:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
case 4:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
}
}
}
}
}
I have a checkbox named counter associated with each row and I need to validate only those rows where counter is checked. I tried using the getElementById for the checkbox and see if it is checked but I'm having trouble determining where the end of the row is for that particular checkbox! :confused:
I have a form that has several textboxes with identical names. I figured out a way to validate them by going row by row in the DOM. The problem is that I have a checkbox associated with each row and I need to validate only those rows that are checked and ignore the ones that aren't. Any ideas on how this might be accomplished? thanks,
Here is my validating procedure:
function isValid(){
var isDecimal_re = /^\d+(\.\d+)+$/; //to check for decimal input
var texts=document.getElementsByTagName("input");
columns=4;
for (i=0; i<texts.length; i++)
{
if (texts[i].type=="text")
{
if (!isDecimal_re.test(texts[i].value))
{
columnId=(i%columns)+1;
rowId=Math.ceil(i/columns)+1;
switch(columnId)
{
case 1:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
case 2:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
case 3:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
case 4:
alert("Invalid Number, has to be decimal");
texts[i].focus();
return false;
}
}
}
}
}
I have a checkbox named counter associated with each row and I need to validate only those rows where counter is checked. I tried using the getElementById for the checkbox and see if it is checked but I'm having trouble determining where the end of the row is for that particular checkbox! :confused: