[jQuery] getting the ID number of a cloned table row
<html>
<body>
Hello folks,
I'm trying to duplicate a row of an existing table using a function
adapted from
<a href="http://www.nabble.com/Add-Table-row-to12989886s27240.html#a13300133" eudora="autourl">
http://www.nabble.com/Add-Table-row-to12989886s27240.html#a13300133</a>
My problem is that I cannot identify the identifier of the last row (of
the original table).
The last row of my table has the form:
<pre><tr class="smfont90"><td><input
name="correctans5" value="1" id="bc5"
type="checkbox"></td><td><textarea
rows="3" name="answer5" id="theans5"
style="width:
250px;"></textarea></td><td><textarea
rows="3" name="feedback5" id="fb5"
style="width:
250px;"></textarea></td></tr>
</pre>The function I'm using is as follows. Two questions:
1. I get an error at the alert - intCurrentRowID is not defined.
What is my error here?
2. Is there a more efficient way of writing the 4 lines starting at point
2 (I'm trying to re-name the feedback and answer IDs and NAMEs
<tt>function duplicateRow(){
// First, lets create the new
row using the last one as template...
var clonedRow = $(
"#myTable tr:last" ).clone();
// Take the current
identifier, some number in the first cell of the row
intCurrentRowId = parseInt( $(
"#bc:last", clonedRow ).html() );
1.---> alert(intCurrentRowID);
// Set the new ID
intNewRowId = intCurrentRowId
+ 1;
// Change the current
identifier of the row to the new one
$( "#bc:last",
clonedRow ).html( intNewRowId );
// Change the Id / Name or
anything you want for the new attribs
2.---> $( "#fb"+ intCurrentRowId , clonedRow ).attr( {
"id" : "fb" + intNewRowId} );
$( "#bc"+
intCurrentRowId , clonedRow ).attr( { "id" : "bc" +
intNewRowId} );
$( "#feedback"+
intCurrentRowId , clonedRow ).attr( { "name" :
"feedback" + intNewRowId} );
$( "#answer"+
intCurrentRowId , clonedRow ).attr( { "name" :
"answer" + intNewRowId} );
// Add to the new row to the
original table
$(
"#myTable").append( clonedRow );
};
</tt>Thanks,
Bruce</body>
</html>