Hi,
I have a problem with validation of dynamically created text boxes.
I have used the following code which was posted by you in one of the forums.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;

charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function addR(){
var oRows =

document.getElementById('tab').getElementsByTagName('tr');//rows

collection
var root = oRows[0].parentNode;//the root
var newRow = oRows[1].cloneNode(true);//the cloned row
var oFields = newRow.getElementsByTagName('input');//the fields

collection in row
for(var i=0;i<oFields.length;i++){//sets the new names for the fields

in the new row
oFields[i].setAttribute('name',oFields[i].getAttribute('name')+'_'+(o

Rows.length-1));
}
root.appendChild(newRow);//append the cloned row as a new row
}
</script>
</head>
<body>
<table id="tab" width="500" border="0" cellpadding="0"

cellspacing="1" bgcolor="#CCCCCC">
<tbody>
<tr>
<td>TEXT</td>
<td>TEXT</td>
<td>TEXT</td>
<td>TEXT</td>
<td>TEXT</td>
</tr>
<tr>
<td><input type="text" name="tex1"></td>
<td><input type="text" name="tex2"></td>
<td><input type="text" name="tex3"></td>
<td><input type="text" name="tex4"></td>
<td><input type="text" name="tex5"></td>
</tr>
</tbody>
</table>
<br>
<br>
<input name="But" type="button" value="Add a new row"

onclick="addR()">
</body>
</html>


I tried the following validation but the problem is with text-box names after a new row is created.It retains the old values due to which the function gives wrong results.


function validate(){
var oRows = document.getElementById('tab').getElementsByTagName('tr');//rows collection
var root = oRows[oRows.length-2].parentNode;//the root
var oFields = root.getElementsByTagName('input');//the fields collection in row

if(oFields[0].value=='')
{
alert('Degree field is empty');
oFields[0].focus();
return false;
}

else if(oFields[1].value=='')
{
alert('Institution field is empty');
oFields[1].focus();
return false;
}

else if(oFields[2].value=='')
{
alert('Year of Passing is empty');
oFields[2].focus();
return false;
}

else if(!isYear(oFields[2].value)) //valid yop
{
alert('Invalid Year!Enter 4 digit numbers in the form yyyy');
oFields[2].focus();
return false;
}

else if(oFields[3].value=='')
{
alert('Enter Percentege');
oFields[3].focus();
return false;
}


else if(!isInteger(oFields[3].value))
{
alert('Invalid Percentage!! Enter only numbers');
oFields[3].focus();
return false;
}

return true;

} //validate

I am unable to understand which is the parent of the newly created row and the names of the text boxes.
Please help me with this validation as soon as possible.

Regards
asm