In the habit of supplying exact code...
document.addEvent( 'domready' , function() {
var row_counter = 0;
$('addRow').addEvent('click', function() {
new Element('tr').adopt(
new Element('td').adopt(new Element('input', {name:
'item['+row_counter+'][item_id]'})),
new Element('td').adopt(new Element('input', {name: 'item[
+row_counter+'][item_name]'}))
).injectInside('myTbody');
row_counter++;
});
});
This is very basic JS usage. If you can get the hang of using element, it's
weird for me that you're troubled with the addition of a counter....
On Sun, Dec 19, 2010 at 9:37 PM, Sean McArthur <[email protected]>wrote:
> So add a counter that is set initially to the number of rows, and increases
> after inserting each number.
>
>
>
>
> On Sun, Dec 19, 2010 at 11:32 AM, lidgold <[email protected]>wrote:
>
>> Thanks Arian,
>> as you suppposed I'm using 1.2. I've added the attributes as you
>> suggested, and now it works.
>> Still some problems with item number.
>> My goal is to obtain an array of items, so I should have
>>
>> <tr>
>> <td><input id="item_id" name="item[0][item_id]" value="" /></td>
>> <td><input id="item_name" name="item[0][item_name]" value="" /></td>
>> </tr>
>>
>>
>> <tr>
>> <td><input id="item_id" name="item[1][item_id]" value="" /></td>
>> <td><input id="item_name" name="item[1][item_name]" value="" /></td>
>> </tr>
>>
>> and so on for each new row.
>>
>> This way the resulting array will be:
>>
>> Array ( [0] => Array ( [item_id] => 25 [item_name] =>'one name' ) [1] =>
>> Array ([item_id] => 26 [item_name] =>'another name') )
>>
>> If I have no progressive number after lap, I will get:
>>
>> Array ( [0] => Array ( [item_id] => 25 [item_name] =>'one name' ) [1] =>
>> Array ([item_id] => 26) [2] => Array ([item_name] =>'another name') )
>>
>> item_id and item_name of the second row becomes two separate arrays.
>> If I post them like this, I can't store them inside my table.
>>
>> Any suggestion?
>> Thanks again.
>>
>
>
--
Arieh Glazer
אריה גלזר
052-5348-561
http://www.arieh.co.il
http://www.link-wd.co.il