SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dropdown menu - select option to show multiple <div> items.

    Hi,

    I'm using a bit of Javascript to display content based on the dropdown selection:
    http://jsfiddle.net/mcgarriers/wjLXk/

    However, I would like it when the user selects "show two" that it shows the 2 div elements rather than specifically div2.

    And for "show three" it would show all 3 divs.


    How do I achieve this?


    Many thanks for any pointers.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by invision2 View Post
    However, I would like it when the user selects "show two" that it shows the 2 div elements rather than specifically div2.

    And for "show three" it would show all 3 divs.
    You would loop through the select box values twice. Once to hide all of the divs, and a second time to show the divs. until you get to the one that was selected. Once you reach the one that was selected, you can break out of the loop.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by invision2 View Post
    However, I would like it when the user selects "show two" that it shows the 2 div elements rather than specifically div2.

    And for "show three" it would show all 3 divs.
    You would loop through the select box values twice. Once to hide all of the divs, and a second time to show the divs. until you get to the one that was selected. Once you reach the one that was selected, you can break out of the loop.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

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
  •