...

View Full Version : Not able to add validation to the dynamic rows!



jsbeginner29
06-29-2012, 07:47 AM
Hi all,

I have a dynamic table in which I can add rows using an add button.. The problem here is I am not able to validate the rows that are added dynamically.

My Java Script code is as follows for adding the new rows:


var table = document.getElementById('tbodyId');
var row = table.insertRow(rownumber);


var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.id="active";
element1.name="active";
element1.onchange = "validation();";
cell1.appendChild(element1);


now my problem is the validation() function is not getting called when I am entering data into the textbox. Can anyone please help me and enlighten me as to what is wrong with this code?

DaveyErwin
06-29-2012, 01:24 PM
<!doctype html>
<head><title></title>
</head><body>
<table>
<tbody id="tbodyId">
</table>
<script>
var table = document.getElementById('tbodyId');
for(var i = 0; i<3; i++){
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.name="active[]";
element1.onchange = function(){validation(this)};
cell1.appendChild(element1);
}
function validation(el){alert(el.value)}
</script>
</body></html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum