mercredi 31 décembre 2014

Dynamically adding dropdown and Textbox by user


can anyone help me on the below I developed a code below for dynamically adding text boxes but i need to do the same for drop down boxes and the value should be taken from servlet by using ajax ...pls anyone help me ...



<HTML>
<HEAD>
<title>Add/Remove dynamic rows</title>
<SCRIPT lang="javascript">
function addRow(tableID)
{
var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var counts = rowCount - 1;
var cell1 = row.insertCell(0);
var houseNo = document.createElement("input");
houseNo.type = "text";
houseNo.name = "houseNo";
cell1.appendChild(houseNo);
var cell2 = row.insertCell(1);
var street = document.createElement("input");
street.type = "text";
street.name = "street";
cell2.appendChild(street);
var cell3 = row.insertCell(2);
var city = document.createElement("input");
city.type = "text";
city.name = "city";
cell3.appendChild(city);
var cell4 = row.insertCell(3);
var country = document.createElement("input");
country.type = "text";
country.name = "country";
cell4.appendChild(country);
}
</SCRIPT>
</HEAD>
<BODY>
<form action="submit" method="post">
<table>
<tr>
<td>
Reg No
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>
<td><INPUT type="text" name="regNo" /></td>
</tr>
<tr>
<td>Name</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</td>
<td><INPUT type="text" name="name" /></td>
</tr>
<tr><td><br/><b>Addresses</b></td>
</tr>
</table>
<TABLE id="addressesTable">
<TR>
<TD>House No</TD>
<TD>Street</TD>
<TD>City</TD>
<TD>Country</TD>
</TR>
<TR>
<TD><INPUT type="text" name="houseNo" /></TD>
<TD><INPUT type="text" name="street" /></TD>
<TD><INPUT type="text" name="city" /></TD>
<TD><INPUT type="text" name="country" /></TD>
</TR>
</TABLE>
<INPUT type="button" value="Add More" onclick="addRow('addressesTable')" />
<input type="submit" value="SUBMIT" />
</form>
</BODY>




Aucun commentaire:

Enregistrer un commentaire