Results 1 to 3 of 3

Thread: Show/Hide content with multiple selection list

  1. #1
    Join Date
    Oct 2008
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Show/Hide content with multiple selection list

    Hi:

    The following code works great to display content for drop-down list when the user selects only 1 item at a time.

    The main problem - How could I change JavaScript to work if multiple items in the list are selected and then content is displayed for each list item chosen?



    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
     
    <script type="text/javascript">
    function showDivs(prefix,chooser) {
            for(var i=0;i<chooser.options.length;i++) {
                    var div = document.getElementById(prefix+chooser.options[i].value);
                    div.style.display = 'none';
            }
            var div = document.getElementById(prefix+chooser.value);
            div.style.display = 'inline';
    }
    window.onload=function() {
      document.getElementById('selectedOptions').value='0';//set value to your default
    }
    </script>
     
    </head>
    <body>
    
    <table>
    	<tr>
    		<td><select size="4" multiple id="selectedOptions" onchange="showDivs('div',this)">
          <option value="0" selected>select</option>
          <option value="1">Cancelled request </option>
         <option value="2">Client hierarchy </option>
                      <option value="2">Missing, 
                      incorrect groups/contracts </option>
                      <option value="3">Clarify Comment Section 
                      </option>
                      <option value="4">Insufficent 
                      effective date/testing leadtime </option>
                      <option value="5">Other 
                      - (type in reason after dash) </option>
        </select><br>
          <strong>Catergory:</strong> <span id="div0" style="display:none;"></span>
    <span id="div1" style="display:none;">Admin O/R</span>
    <span id="div2" style="display:none;">Client Enrollment Info</span>
    <span id="div3" style="display:none;">Requirements</span>
    <span id="div4" style="display:none;">Validation Error</span>
    <span id="div5" style="display:none;">Other</span>
    </td>
    	</tr>
    </table>    
    </body>
    </html>
    Appreciate help in advance.

    Thanks
    Last edited by Snookerman; 05-07-2009 at 05:50 PM. Reason: added [html] tags, added “Resolved” prefix

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <script type="text/javascript">
    function showDivs(prefix,chooser) {
            for(var ary=[],i=0;i<chooser.options.length;i++) {
                    var div = document.getElementById(prefix+chooser.options[i].value);
                    div.style.display ='none';
                  if (chooser.options[i].selected) ary.push(chooser.options[i])
    
            }
     for (var div,z0=0;z0<ary.length;z0++){
      div=document.getElementById(prefix+ary[z0].value);
      if (div) div.style.display = 'inline';
     }
    }
    window.onload=function() {
      document.getElementById('selectedOptions').value='0';//set value to your default
    }
    </script>

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    mmalik (05-07-2009)

  4. #3
    Join Date
    Oct 2008
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks so much vwphillips for your help. It works perfectly

    Thank again.

    Take care

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
  •