|
please help me with dynamically adding textfields
I have this script that adds a new row textfields of text fields when the user clicks the button...
but I want the function to add 5 new fields of varying sizes instead of just 2.
can anyone help?
cheers
bevan
the code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="Javascript" type="text/javascript">
var Cnt=2;
function addField(area,field,limit) {
if(!document.getElementById) return;
var field_area=document.getElementById(area);
var li=document.createElement('LI');
field_area.appendChild(li);
var tb=document.createElement('INPUT');
tb.name='friend_A'+Cnt;
li.appendChild(tb);
tb=tb.cloneNode(false);
tb.name='friend_B'+Cnt;
li.appendChild(tb);
Cnt++;
}
</script>
</head>
<body>
<form name="frm" method="POST">
<br />
<ol id="friends_area"><li >
<input name="friend_1" type="text" id="friend_A1" size="4" />
<input name="friend_12" type="text" id="friend_B1" size="20" />
<input name="friend_123" type="text" id="friend_C1" size="10">
<input name="friend_1234" type="text" id="friend_D1" size="10">
<input name="friend_12345" type="text" id="friend_E1" size="7">
</li>
</ol>
<input type="button" value="Add Another row" onClick="addField('friends_area','friend_',10);" />
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<br />
</form>
</body>
</html>
|