Originally posted by giri shetty:
Hi guys,
can you please explain me how to add textfields in a jsp page when i click a button .if i click a button three times three buttons should be added to that jsp page.
thanks in advance
Do you want to add textfields or button.
There are two ways to add element dynemically.
(1) using document.write() property
(2) using document.createElement() property
Here is an example using (2) property.
------------------------------------
<html><head></head><body>
<form action=inputox.html name="form1">
<table>
<tbody id="tbody1">
<tr>
<td>
This is Row 1
<input type="button" value="Click to Add a Row" name="button1" >
</td>
</tr>
<tr id="lastTR">
<td id="lastTD">
This is Row 2
</td>
</tr>
</tbody>
</table>
<input type=submit>
</form>
<script>
textCount = 1;
function AddRow()
{
var tbody1 = document.getElementById("tbody1");
var lastTR = document.getElementById('lastTR');
var newTR = document.createElement('TR');
var newTD = document.createElement('TD');
tbody1.insertBefore(newTR, lastTR);
newTR.appendChild(newTD);
newTD.innerHTML="<input type=text name=textField" + textCount +">";
textCount++;
}
</script>
</body></html>
--------------------------------------
Please use on click proprty to call AddRow() function at first button ie. "button1". I was not able to post if i insert this property at button1.
Hope this will helpful to you.
[ January 26, 2004: Message edited by: himanshu patel ]
[ January 26, 2004: Message edited by: himanshu patel ]