I have an existing HTML table, part of a form where the user enters GPS points. The user also has the option to upload GPS data points. I\'d like to have a button the user
Why use Jason's perfectly sensible solution when you could use an over-engineered version?
;o)
function addRow() {
var $newRow = $('#gpsTable tbody tr:last-child').clone();
var newid = $newRow.children().eq(1).find('.StdTableData input').attr('id').match(/\d+/);
newid = parseInt(newid[0]) + 1;
var newXid = 'x' + newid;
var newYid = 'y' + newid;
$newRow.children().eq(0).find('.StdTableData').text(newid);
$newRow.children().eq(1).find('.StdTableData input').attr({id:newXid,name:newXid}).val('');
$newRow.children().eq(2).find('.StdTableData input').attr({id:newYid,name:newYid}).val('');
$('#gpsTable tbody').append($newRow);
}
Oh, and just in case you're not quite so familiar with jQuery, here's some code that will turn your Sequence text heading into a button you can click to add a row.
$(document).ready(function() {
$('th:first').click(function() {
addRow();
});
});