I am dynamically creating a table with input fields based on an onchange from an input field.
the following is my code
Code: Select all
function InsertFields(no) {
var mytable=document.getElementById("e;flight_table"e;);
var mycells = mytable.getElementsByTagName("e;TR"e;).item(0);
mytablebody = document.createElement("e;TBODY"e;);
// check to see if elements were already created
if(mytable.rows.length>1){
// delete rows
for(i=1;i<mytable.rows.length;i++){
mycell = mytable.rowsїi];
alert(mycell);
//mytable.removeChild(mycell);
}
}
for(i=1;i<=no;i++) {
mycurrent_row=document.createElement("e;TR"e;);
//for(r=0;r<2;r++) {
mycurrent_cell=document.createElement("e;TD"e;);
currenttext=document.createTextNode("e;Route#"e;+i+"e;: "e;);
mycurrent_cell.appendChild(currenttext);
mycurrent_row.appendChild(mycurrent_cell); // end row
mycurrent_cell = document.createElement("e;TD"e;); // second cell
myinput = document.createElement("e;INPUT"e;);
myinput.setAttribute("e;type"e;,"e;text"e;);
myinput.setAttribute("e;name"e;,"e;Route"e;+i);
//currenttext=document.createTextNode('<input type="e;text"e; name="e;Route'+i+'"e;>');
mycurrent_cell.appendChild(myinput);
mycurrent_row.appendChild(mycurrent_cell); // end row
//}
mycells.appendChild(mycurrent_row);
}
mytablebody.appendChild(mycells);
mytable.appendChild(mytablebody);
// mybody.appendChild(mytable);
// mytable.setAttribute("e;border"e;,"e;2"e;);
// alert('tbody has '+mytable.rows.length);
}Code: Select all
<table id="e;flight_table"e; name="e;flight_table"e; border="e;1"e;><tr><td>Please Indicate Number of Routes</td><td>
<input type="e;text"e; name="e;Flights"e; id="e;Flights"e; onchange="e;InsertFields(this.value)"e; size="e;20"e;></td></td></tr></table>well it ends up just adding rather than "replacing"
so im trying to have the function check wether to replace or add more input fields...but to no avail
I want to be able to add or remove or replace the number of input fields based on the visitors input?
Kendall