Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic table rows...

Status
Not open for further replies.

kanghao

IS-IT--Management
Jul 4, 2004
68
KR
I mean I want to add table rows in javascript and I tried. but I had a infinate loop.
the input elements in each table row are named, so they can be processed by action pages or servlets. the names are "string"_"number" and they should be incresed by 1.

here is the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--
function getNNStr(str_to_test) {// get not number string
var regex = new RegExp("[A-Za-z_]*");
if (str_to_test.match(regex)) {
return regex.exec(str_to_test);
} else {
return str_to_test;
}
}

function getNextNumber(str_to_test){
var parsed_number = parseInt(str_to_test.match(/\d+$/));
if (isNaN(parsed_number)){
return 0;
} else {
return parsed_number+1;
}
}

function getNewName(str){
return getNNStr(str)+(getNextNumber(str)+"");
}

function getNewNamedNode(old_node){
var child_nodes = old_node.childNodes;
for(i=0;i<child_nodes.length;i++){
if(child_nodes.name != undefined && old_node.nodeType == 1){
child_nodes.name = getNewName(child_nodes.name);
}
if(child_nodes.nodeName == "TD"){
getNewNamedNode(child_nodes);
}
}
return old_node;
}

function inputOneRowToList(node_id){
var tbl = document.getElementById(node_id);
var tbl_rows = tbl.rows;

var lastrow = tbl_rows[tbl_rows.length-1];
var new_last_node = lastrow.cloneNode(true);
lastrow.parentNode.appendChild(getNewNamedNode(new_last_node));

}

// -->
</script>

</head>
<body>
<form action="frmAction.htm">
<input type="submit" value="submit">
<span onclick="alert(getNextNumber('tb_aL_ist0'))">temp...</span>
<br/>
<span onclick="inputOneRowToList('tblList')">click...</span>
<table border="1" cellpadding="3" cellspacing="0" id="tblList">
<tr>
<td>no</td><td>
EmpNO<input name="emp_no0"/><input name="Button1" type="button" value="Search" />
</td><td>
EmpName<input name="emp_name0" type="text" value="User K" />
</td>
<td>
<input name="chk0" type="checkbox" /></td>
</tr>

</table>
<br />
</form>
</body>
</html>
 
What problem are you having? What does nyour code do that it should not / does not do that it should? What error(s) are you seeing? What browser(s) have you tried this in?

Help us to help you - give us some details.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top