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
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hide some options of dropdown menu

    Hi,

    i have a form with some checkbox and dropdown list

    if T-shirt option is checked i want to hide the ball options from the dropdown list, and if Ball option is checked i want to hide the T-shirt options

    how to do that

    Regards,

    <html>

    <head>

    <title>test</title>
    </head>

    <body>

    <form name=calc >
    <input type="checkbox" name="tshirt" value="ON">T-shirt
    <select size="1" name="description">
    <option>Nike</option>
    <option>Addidas</option>
    <option>Fila</option>
    <option>Basket Ball</option>
    <option>Football</option>
    <option>Tennis Ball</option>
    </select></p>
    <input type="checkbox" name="ball" value="ON">Ball
    </form>

    </body>

    </html>

  • #2
    New to the CF scene
    Join Date
    Mar 2005
    Location
    Toronto
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to populate the select box dynamically using pre-built arrays. For example,
    var aBalls = new Array ("Basket Ball", "Football", "Tennis Ball");
    var aTshirts = new Array ("Nike", "Addidas", "Fila");

    Initially, you populate your select box with one set of values only.

    Then, attach a function on the onClick event to the check-boxes. For example,

    function hide(){
    if(document.calc.tshirt.checked){
    for(var i=0; i<aTshirts.length;i++){
    document.calc.description.options[i]=new Option (aTshirts[i]);
    }
    }
    if(document.calc.ball.checked){
    for(var i=0; i<aBalls.length;i++){
    document.calc.description.options[i]=new Option (aBalls[i]);
    }
    }

    }

    You are probably better off using radio buttons instead of check-boxes.

    Hope this helps.

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how about if i want to put values to the dropdown list items???


    Regards,


    reasr


  •  

    Posting Permissions

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