SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    Toronto
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form values into an array

    What I am trying to do is read a set of values from a drop down menu and put them into an array. Then I want to check a value against the array with an IF statement.

    The problem I am having is how to read the values of the drop down menu in a loop.

    I can successfully read the selected value just fine but I'm not sure how and where to incorporate the variable for the loop.

    var = (document.f1.Alloy.options[document.f1.Alloy.options.selectedIndex].value);

    Also, it seems everytime I try to read/write a value using a syntax similar to the above any kind of loop terminates once through. Am I doing something wrong?

    Thanks
    Last edited by loomer; Jun 2, 2003 at 10:13.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var selectElem = document.f1.Alloy, i = 0, opt;
    while ( opt = selectElem.options[i++] )
    {
    if ( opt.value == someValue )
    {
    // whatever
    }
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Member
    Join Date
    May 2003
    Location
    Toronto
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.. That basically optimized the code I had but I've been stuck on the same point all day(ahhh!)..

    I would like to click a button and change the selectedindex of the drop down. The code can successfully check the drop down to see if it has the content is should before making it the selectedindex. For example if the drop down doesn't contain an I-Beam listing then the I-Beam button will do nothing for that menu, but if I-Beam is in the drop down it will 'select' it.

    So I'm passing a variable (number but could be text if need be)into the function that represents the product. If it finds the product in the list then it should make it the selectedindex but instead of doing that's just choosing the listing with that number and not the listing that has that value.

    eg. if I am searching for an item with a value of 4 then it will just select the 4th item in the drop down instead of selecting the product with the value 4.

    Please.. This is so simple but for some reason it's taking me forever.

    Thanks

  4. #4
    SitePoint Addict
    Join Date
    May 2003
    Location
    The Netherlands
    Posts
    391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you post what you have so far?


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
  •