Results 1 to 3 of 3

Thread: Show/hide div in select menu

  1. #1
    Join Date
    Oct 2009

    Show/hide div in select menu

    Hi all-

    Having some compatibility issues with my script to show different divs when a different option is selected in a drop-down menu (select form). It works in Firefox, but not Safari or IE). I'm sure this is really simple but I'm pretty new at this.

    <script type='text/javascript'>
    function showDiv(idOfDiv) {
    document.getElementById(idOfDiv).style.display = 'block';
    function hideDiv(idOfDiv) {
    document.getElementById(idOfDiv).style.display = 'none';


    <option name="fieldName" id="field1" onclick="showDiv('AirOptions'); hideDiv('OceanOptions'); hideDiv('DomesticOptions');" onblur="hideDiv('div1');" selected="selected"/>Air Service</option>
    <option name="fieldName" id="field2" onclick="showDiv('OceanOptions'); hideDiv('AirOptions'); hideDiv('DomesticOptions');">Ocean Service</option>
    <option name="fieldName" id="field3" onclick="showDiv('DomesticOptions'); hideDiv('AirOptions'); hideDiv('OceanOptions');" onblur="hideDiv('div3');">Domestic Service</option>

    <div id="AirOptions" style="display:none;">Air Services</div>
    <div id="OceanOptions" style="display:none;">Ocean Services</div>
    <div id="DomesticOptions" style="display:none">Domestic Services</div>

    I could really use some help! Thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Your code is very off from what I would think to work in any browser??

    HTML Code:
    <META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <STYLE type=text/CSS>
    <SCRIPT type="text/javascript">
    function showDiv(divIndex) {  var f=document.forms[0];  var d=f.getElementsByTagName('div');
    d[divIndex].style.display = 'block';
    <META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
    <BODY scroll="auto">
    <select onchange="showDiv(this.value); ">
    <option value="0" selected>Air Service</option>
    <option value="1">Ocean Service</option>
    <option value="2">Domestic Service</option>
    <div style="display:block;">Air Services</div>
    <div style="display:none;">Ocean Services</div>
    <div style="display:none">Domestic Services</div>

  3. #3
    Join Date
    Oct 2009
    Thanks! That totally works. One more question though: Is it possible to have a sub-select menu within one of the hidden divs? Would I just change the value of the option? That seems to screw up the hidden div after it (Domestic Services)

    For example:

    <select onchange="showDiv(this.value); ">
    <option selected="selected">Select One</option>
    <option value="0" selected>Air Service</option>
    <option value="1">Ocean Service</option>
    <option value="2">Domestic Service</option>

    <div style="display:none;">Air Services</div>
    <div style="display:none;">Ocean Services

    <select onchange="showDiv(this.value); ">
    <option selected="selected">Select One</option>
    <option value="4" selected>FCL</option>
    <option value="5">LCL</option>

    <div style="display:none;">FCL Options</div>
    <div style="display:none;">LCL Options</div>

    <div style="display:none">Domestic Services</div>

    Thanks in advance!

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