HTML View<script language="javascript">
function add_opt_row() {
var rows = document.getElementById('formtable').getElementsByTagName('tr');
var highest_id = 0;
var total_rows = rows.length;
for (var index = 0; index < total_rows; index++) {
if (rows[index].id.substr(0, 3) == 'opt' && !isNaN(rows[index].id.substr(3))) {
if (Number(rows[index].id.substr(3)) > highest_id) highest_id = Number(rows[index].id.substr(3));
}
}
// Create 2 new table cells
var cell1 = document.createElement('td');
var cell2 = document.createElement('td');
// Create a new input textbox in each
var inputbox = document.createElement('input');
inputbox.type = 'text';
inputbox.name = 'opt_title[]';
inputbox.maxLength = 255;
inputbox.size = 40;
cell1.appendChild(inputbox);
inputbox = document.createElement('input');
inputbox.type = 'text';
inputbox.name = 'opt_url[]';
inputbox.maxLength = 255;
inputbox.size = 40;
cell2.appendChild(inputbox);
// Create new row & add tds to row
var newrow = document.createElement('tr');
newrow.id = 'opt' + (highest_id+1);
newrow.appendChild(cell1);
newrow.appendChild(cell2);
// Add rows to appropriate place
document.getElementById('opt_controls').parentNode.insertBefore(newrow, document.getElementById('opt_controls'));
}
</script>