Posts Tagged ‘jquery’

jquery add a table row

May 13, 2008 4 comments

I needed to add a table row to the bottom of a form.  Jquery to the rescue. The form has a series of rows that record a start date and an end date.  But the user can opt to create more input rows if they so choose, kicking off a little dhtml to extend the size of the form.

Here’s what I ended up using to add a row to the bottom of the table:

function onAddDateRange() {
var lastRow = $(‘#date_ranges tr:last’).clone();
var id = parseInt($(‘.id’, lastRow).html()) + 1;
$(‘[name]:first’, lastRow).attr(‘name’, ‘week_start_’ + id);
$(‘[name]:last’, lastRow).attr(‘name’, ‘week_end_’ + id);
$(‘.id’, lastRow).html(id);

Categories: Uncategorized Tags: