...

View Full Version : creating/dealing with an indeterminate number of table row objects?



knave
08-17-2005, 03:51 AM
what i have is a page with a table full of form fields, and a button that, when i click it, should add another row into said table. i want the user to be able to add and delete as many as they want, and they all would have id's such as 'field1', 'field2', etc. the thing is, i can't seem to write a static function to handle this indeterminate amount of html objects. i have an example of the page here (http://www.coro36ink.com/e/table.html).

i thought perhaps i could use eval():



function modifyField(num) // num of the row to work with
{
eval('field'+num+'.someproperty = "somevalue";');
}


thus i could call it like modifyField(1) to have it work with document.field1, etc. however, this doesnt work. even when i hardcode the object in (a span with an id="field1"), i get the error "field1 is not an object", when i try to refer to it from within an eval().

is there ANY way to do this with javascript? i really dont want to have to put such a repetetive load on a server-side script...

nikkiH
08-17-2005, 02:39 PM
Why do you need eval?

x = "1";
element = document.getElementById('field'+x);

do whatever with element...

knave
08-17-2005, 03:34 PM
ah, thank you. i'm retarded, i just needed to use getElementByID. (it bears mentioning that I've been away from javascript for a while, so I've forgotten a few things :o ) Thanks a bunch, though.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum