CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   jQuery Cloning and inserting (http://www.codingforums.com/showthread.php?t=176331)

Starmaster 09-06-2009 01:58 PM

Cloning and inserting
 
I have the following html code:

Code:

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

and JavaScript code:

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?


All times are GMT +1. The time now is 02:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.