I have a java script function which uses appendChild( createTableCell) to build a dynamic table as required. Every time an item is added the variable num in incremented and this function is called to add a row in a table to provide detailed information about the item added.
// num is number of the object the table row references
function addTableRow(num) {
// add new table row to dynamic table
var tr = document.createElement('TR
');
tr.id = 'dynamicRow' + num;
tr.setAttribute( 'id', 'dynamicRow' + num );
tr.appendChild( createTableCell( num ) );
tr.appendChild( createTableCell( '<select name="type'+num+'"><option
>Select Glass</option></select>' ) );
tr.appendChild( createTableCell( '<select name="design'+num+'" class="style15"><option>Cl
ear - No Design</option></select>' ) ); tr.appendChild( createTableCell( '<input name="width'+num+'" >' ) );
tr.appendChild( createTableCell( '<input name="height'+num+'" >' ) );
tr.appendChild( createTableCell( '<input name="price'+num+'" >' ) );
$('dynamicTable').appendCh
ild( tr );
}
The problem is that I need to dynamically populate the select lists used in the table. The select lists will be identical from row to row, but need to change when the page loads.
If I build a template in html / php and call it from the java script function I think it will do what I need. The template will be dynamically populated on the page load, and the java script function can call it as required.
// Sample Template - the # needs to be changed to the row number num when insert into the table
<tr id="dropdownTemplate">
<td name="glassNum">Glass Number</td>
<td><select name="type#"><option>Selec
t Glass</option></select></t
d>
<td><select name="design#"><option>Cle
ar - No Design</option></select></
td>
<td><input name="width#"></td>
<td><input name="height#"></td>
<td><input name="price#" disabled></td>
</tr>
I have verified that with a little php I can populate the select list as needed. I can insert the template, but I havent figured out how to change the names so that each row represents the num object. I probably shouldnt insert it, but should clone it, rename it, and then insert the clone. Need a little direction here.
Thanks
Start Free Trial