...

View Full Version : jQuery Cloning and inserting



Starmaster
09-06-2009, 01:58 PM
I have the following html code:



<table>
...
<tr id="InputRow">
<td>
<input type="text" name="..." value=""/>
<span>
</span>
</td>
</tr>
</table>


and JavaScript code:



function AddRow(far)
{
var rowclone=$('#InputRow').clone(); //clone the row
for (i=0; i<far.length; i++)
{
if (i == 0)
{
$('#InputRow').find('input').val(far[i]['id']);
$('#InputRow').find('span').html(far[i]['fname']);
}
else
{
rowclone.find('input').val(far[i]['id']);
rowclone.find('span').html(far[i]['fname']);
$('#InputRow').nextAll("tr:last").after(rowclone); //insert a new row after the existing at the end
}
}
}

$(function()
{
AddRow(ar); //JSON object with a simple array
}
);


So what I need to do is to simply clone the row, substitute new values from an array and insert it at the end of existing row (if array's size more then 1). But this doesn't work! Where is an error?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum