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 Coder
    Join Date
    Aug 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding up dynamically created variables

    Hello,

    If I have 2 or more javascript variables like this

    var id_1234 = 23;
    var id_5678 = 27;

    var total = id_1234 + id_5678; \\Ans 50


    How could I add them up if I don't know the part after id_ in the variable name??

    (that is being created dynamically by the perl script depending on the ID numbers the user inputs)

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Can you make the perl script generate an id array instead of random variable names, like:

    id[1234] = 13;
    id[4513] = 27;

    And then you can manipulate the array. Or, you can loop over every variable in the window object to find things that match the pattern of your variable names, but that sux.

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Beagle,
    The "id array" would work brilliantly.
    Thanks for the idea.


  •  

    Posting Permissions

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