SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why the &bleep& doesn't this work?

    I have a c++ application that runs a bunch of simulations and updates my website with the results. Part of the update is an input form which reflects the current state of the system being simulated.

    On this input form Ihave a series of drop downs all named as follows:

    chooser1
    chooser2
    chooser3
    ...

    It's more or less like an array

    So then to get the value from these drop downs I am doing this

    for (var i = 1; i<n; i++){
    var dropName = "chooser" + i;
    selectedValue = document.getElementById(dropName).value;
    ...
    }
    But the javascript is hanging up on the getElementById statement (I know this because I've commented it out and the JS flows beyond that point in the code). I have also confirmed that the dropName that is created with the concatenation is accurate.

    What am I doing wrong. And is there any way to do with with a proper array rather than this 'hack' array?

  2. #2
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi snarky,

    You can try using the var statement with the selectedValue variable if you haven't already since ie will reference an id with just the id name.

    Two, instead of your hack you can use the selectedIndex property with an onchange event.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    ok, i figured out what was happening here and my approach was workable, but my execution was not, depending on the simulation state not all of the 'choosers' were being created so I had to wrap this around my logic

    if (document.getElementById(dropName)){...}
    (I'm sure none of you really care, but I always try to close the loop on my questions for those kind souls who use the search feature.)


Bookmarks

Posting Permissions

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