Hi
I'm currently developing a form with a dynamic table. initially the table is
populated with data and at the end of each row there are two buttons:
addLevel and addItem. Each button creates a new row below the row the button
is in. The new row also has these buttons, but when pressing one of these
buttons, nothing happens.
Can someone tell me why?
here's the code to the addLevel button:
<script>
doc = document;
cbsTotal =0;
cbsLevel =0;
function addLevelTo(id,i ndex) {
var tbl = doc.getElementB yId(id);
var cbsHidden = doc.getElementB yId("cbsTotal") ;
var rowID = (showRowCell (index)) + 1;
cbsLevel++;
if(id == "cbsBody"){
var newrow = tbl.insertRow(r owID);
alert("check: " + id);
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "red";
var newdata ="<div align='left'><i nput name='cbs" + cbsTotal + "
type='text' id='cbs" + cbsTotal + " size='20' maxlength='40'> </div>";
newcol.innerHTM L = newdata;
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "green";
var newdata = "<div align='left'><i nput name='cbs" + cbsTotal + "
type='text' id='cbs" + cbsTotal + " size='20' maxlength='40'> </div>";
newcol.innerHTM L = newdata;
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "blue";
var newdata = "<div align='left'><i nput name='cbs" + cbsTotal + "
type='text' id='cbs" + cbsTotal + " size='20' maxlength='40'> </div>";
newcol.innerHTM L = newdata;
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "blue";
var newdata = "<input type='button' name='Add Level' value='Add Level'
onClick='addLev elTo('cbsBody', this);'> <input type='button' name='Add Item'
value='Add Item' onClick='addRow To('cbsBody');' >";
newcol.innerHTM L = newdata;
cbsTotal++;
cbsHidden.value = cbsTotal;
}else{
//do nothing
}
updateRowCounte rs(tbl);
}
</script>
<script>
//housekeeping functions
function updateRowCounte rs(form){
var sel1 =form.insertInd ex
var sel2 =form.deleteInd ex
sel1.options.le ngth =0
sel2.options.le ngth =0
for (var i =0;i <theTableBody.r ows.length;i++) {
sel1.options [i ] ==new Option(i,i)
sel2.options [i ] ==new Option(i,i)
}
form.removeRowB tn.disabled =(i==0)
}
</script>
<script>
function showRowCell (element) {
var cell, row;
if (element.parent Node) {
do
cell = element.parentN ode;
while (cell.tagName.t oLowerCase() != 'td')
row = cell.parentNode ;
}
else if (element.parent Element) {
do
cell= element.parentE lement;
while (cell.tagName.t oLowerCase() != 'td')
row = cell.parentElem ent;
}
return row.rowIndex;
}
</script>
I'm currently developing a form with a dynamic table. initially the table is
populated with data and at the end of each row there are two buttons:
addLevel and addItem. Each button creates a new row below the row the button
is in. The new row also has these buttons, but when pressing one of these
buttons, nothing happens.
Can someone tell me why?
here's the code to the addLevel button:
<script>
doc = document;
cbsTotal =0;
cbsLevel =0;
function addLevelTo(id,i ndex) {
var tbl = doc.getElementB yId(id);
var cbsHidden = doc.getElementB yId("cbsTotal") ;
var rowID = (showRowCell (index)) + 1;
cbsLevel++;
if(id == "cbsBody"){
var newrow = tbl.insertRow(r owID);
alert("check: " + id);
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "red";
var newdata ="<div align='left'><i nput name='cbs" + cbsTotal + "
type='text' id='cbs" + cbsTotal + " size='20' maxlength='40'> </div>";
newcol.innerHTM L = newdata;
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "green";
var newdata = "<div align='left'><i nput name='cbs" + cbsTotal + "
type='text' id='cbs" + cbsTotal + " size='20' maxlength='40'> </div>";
newcol.innerHTM L = newdata;
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "blue";
var newdata = "<div align='left'><i nput name='cbs" + cbsTotal + "
type='text' id='cbs" + cbsTotal + " size='20' maxlength='40'> </div>";
newcol.innerHTM L = newdata;
var newcol = newrow.insertCe ll();
newcol.height = 25;
newcol.bgcolor = "blue";
var newdata = "<input type='button' name='Add Level' value='Add Level'
onClick='addLev elTo('cbsBody', this);'> <input type='button' name='Add Item'
value='Add Item' onClick='addRow To('cbsBody');' >";
newcol.innerHTM L = newdata;
cbsTotal++;
cbsHidden.value = cbsTotal;
}else{
//do nothing
}
updateRowCounte rs(tbl);
}
</script>
<script>
//housekeeping functions
function updateRowCounte rs(form){
var sel1 =form.insertInd ex
var sel2 =form.deleteInd ex
sel1.options.le ngth =0
sel2.options.le ngth =0
for (var i =0;i <theTableBody.r ows.length;i++) {
sel1.options [i ] ==new Option(i,i)
sel2.options [i ] ==new Option(i,i)
}
form.removeRowB tn.disabled =(i==0)
}
</script>
<script>
function showRowCell (element) {
var cell, row;
if (element.parent Node) {
do
cell = element.parentN ode;
while (cell.tagName.t oLowerCase() != 'td')
row = cell.parentNode ;
}
else if (element.parent Element) {
do
cell= element.parentE lement;
while (cell.tagName.t oLowerCase() != 'td')
row = cell.parentElem ent;
}
return row.rowIndex;
}
</script>
Comment