I've got two select boxes and a script that adds a new one each time the user presses "add". The first select box is named "from" and the second "to". After the user makes the selection the program runs a query and returns a result depending on the selection made. The program remembers the two selection and when the user adds a new select box, that select box takes the value of the first select box which it shouldn't. I would be very grateful if someone could tell me how to solve this problem. I've attached the code below.
<HTML>
<HEAD>
<TITLE> Add/Remove dynamic rows in HTML table </TITLE>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = true;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = '0';
break;
}
}
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
Bookmarks