www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to display/hide dropdown box due to selection

  1. #1
    Join Date
    Oct 2009
    Posts
    10

    Exclamation How to display/hide dropdown box due to selection

    Hey,
    I've got 3 drop down boxes, the first is 'type' and the 2 others are 'subtypes'.
    Basically, when either of the 2 options from 'type' are selected, I want a specific 'subtype' dropdown to display.

    so far i have...

    <select name="type" id="type" style="width:140px;" >
    <option value="opt1" onchange="document.getElementById('subV').style.display='block'; document.getElementById('subP').style.display='none';">opt1</option>
    <option value="opt2"
    onchange="document.getElementById('subP').style.display='block'; document.getElementById('subV').style.display='none';">opt2</option>
    </select>


    and the other two dropdowns with the style display:none;.

    How do i get this to work as there is no displaying of the 'subtypes'.

    Cheers for any help!!

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The onchange must be in the select, as IE does not support events in option
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Oct 2009
    Posts
    10
    How would I script that?
    From what you saying it would seem that it wouldn't give the option of what is visible depending on the selection?

    Do I have to verify a specific script in the <select> what each option does?

    Sorry, but could you give me a bit more detail?

    cheers.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <script type="text/javascript">
    function toggle(opt) {
    switch(opt) {
        case 'opt1':
            document.getElementById('subV').style.display='block'; document.getElementById('subP').style.display='none';
            break;
        case 'opt2':
            document.getElementById('subP').style.display='block'; document.getElementById('subV').style.display='none';
            break;
        default:
    	alert('not a valid option');
        }
    }
    </script>
    
    </head>
    <body>
    <select name="type" id="type" style="width:140px;" onchange="toggle(this.value);">
    <option value="opt1">opt1</option>
    <option value="opt2">opt2</option>
    </select>
    
    </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles