nikscrasher
Programmer
Hi,
I have a table in which rows can be added one by one, dynamically on clicking the 'addrow' button of the various cells in each row, two drop down lists which are to be dynamic drop downs. That is, based on value selected in first drop down shud get populated. I'm encountering problem doing the 'dynamic dropdown' part. I am unable to read the value stored in first drop down using the DOM structure.
Anyway to overcome this?
Here's my code
<script language="JavaScript" type="text/javascript">
function addRowToTable()
{
var jarr = new Array(191);
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cellEight = row.insertCell(0);
var e8 = document.createElement('select');
e8.setAttribute('name','txtRow' + iteration + '7');
e8.setAttribute('size','1');
//e8.setAttribute('onchange',valueIs);
cellEight.appendChild(e8);
var e81 = document.createElement('option');
/////////////////////////////////////////
// HARDCODING THE DROP DOWN OPTIONS
////////////////////////////////////////
e81.innerText = '-Select -';
e8.appendChild(e81);
var e81 = document.createElement('option');
e81.innerText = 'A';
e8.appendChild(e81);
var e81 = document.createElement('option');
e81.innerText = 'B';
e8.appendChild(e81);
var e81 = document.createElement('option');
e81.innerText = 'C';
e8.appendChild(e81);
var cellNine = row.insertCell(1);
var e9 = document.createElement('select');
e9.setAttribute('name','txtRow' + iteration + '8');
e9.setAttribute('size','1');
cellNine.appendChild(e9);
var e91 = document.createElement('option');
////////////////////////////////////////////
//HARDCODING THE DROP DOWN OPTIONS
////////////////////////////////////////////
e91.innerText = '-Select-';
e9.appendChild(e91);
var e91 = document.createElement('option');
e91.innerText = '10';
e9.appendChild(e91);
var e91 = document.createElement('option');
e91.innerText = '20';
e9.appendChild(e91);
var e91 = document.createElement('option');
e91.innerText = '30';
e9.appendChild(e91);
e9.style.backgroundColor = 'beige';
}
</script>
</HEAD>
<BODY BGCOLOR="#EfEECB" >
<form name="myform" action="" method="post">
<input type="button" value="Add a new row" onclick="addRowToTable();" />
<BR><BR>
<table border="0" id="tblSample" align="center">
<thead><tr>
<TD ALIGN='CENTER'>Test A</TD>
<TD ALIGN='CENTER'>Test B</TD>
</thead></tr>
</table>
<BR><BR>
<P>
<input type="hidden" name="count" value ="">
</P>
</form>
</BODY>
</HTML>
I have a table in which rows can be added one by one, dynamically on clicking the 'addrow' button of the various cells in each row, two drop down lists which are to be dynamic drop downs. That is, based on value selected in first drop down shud get populated. I'm encountering problem doing the 'dynamic dropdown' part. I am unable to read the value stored in first drop down using the DOM structure.
Anyway to overcome this?
Here's my code
<script language="JavaScript" type="text/javascript">
function addRowToTable()
{
var jarr = new Array(191);
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cellEight = row.insertCell(0);
var e8 = document.createElement('select');
e8.setAttribute('name','txtRow' + iteration + '7');
e8.setAttribute('size','1');
//e8.setAttribute('onchange',valueIs);
cellEight.appendChild(e8);
var e81 = document.createElement('option');
/////////////////////////////////////////
// HARDCODING THE DROP DOWN OPTIONS
////////////////////////////////////////
e81.innerText = '-Select -';
e8.appendChild(e81);
var e81 = document.createElement('option');
e81.innerText = 'A';
e8.appendChild(e81);
var e81 = document.createElement('option');
e81.innerText = 'B';
e8.appendChild(e81);
var e81 = document.createElement('option');
e81.innerText = 'C';
e8.appendChild(e81);
var cellNine = row.insertCell(1);
var e9 = document.createElement('select');
e9.setAttribute('name','txtRow' + iteration + '8');
e9.setAttribute('size','1');
cellNine.appendChild(e9);
var e91 = document.createElement('option');
////////////////////////////////////////////
//HARDCODING THE DROP DOWN OPTIONS
////////////////////////////////////////////
e91.innerText = '-Select-';
e9.appendChild(e91);
var e91 = document.createElement('option');
e91.innerText = '10';
e9.appendChild(e91);
var e91 = document.createElement('option');
e91.innerText = '20';
e9.appendChild(e91);
var e91 = document.createElement('option');
e91.innerText = '30';
e9.appendChild(e91);
e9.style.backgroundColor = 'beige';
}
</script>
</HEAD>
<BODY BGCOLOR="#EfEECB" >
<form name="myform" action="" method="post">
<input type="button" value="Add a new row" onclick="addRowToTable();" />
<BR><BR>
<table border="0" id="tblSample" align="center">
<thead><tr>
<TD ALIGN='CENTER'>Test A</TD>
<TD ALIGN='CENTER'>Test B</TD>
</thead></tr>
</table>
<BR><BR>
<P>
<input type="hidden" name="count" value ="">
</P>
</form>
</BODY>
</HTML>