Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating/dealing with an indeterminate number of table row objects?

    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.

    i thought perhaps i could use eval():

    Code:
    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...

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Why do you need eval?

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

    do whatever with element...

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ) Thanks a bunch, though.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •