www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Chained Select, but for a checkbox?

  1. #1
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265

    resolved [RESOLVED] Chained Select, but for a checkbox?

    Ok, so I have a drop-down select menu to select "which company" is responsible for a given project... but if a certain one is selected, I need it to offer a checkbox that says something like "this company only?" ... currently we're only working with 1 company that needs this checkbox, because the rest of the companies we work with, we handle all of their business.

    Any suggestions?

  2. #2
    Join Date
    Nov 2010
    Posts
    1,097
    like so?

    Code:
    <!DOC HTML>
    <html>
    <head>
    <style>
    #cb {display:none}
    </style>
    </head>
    
    <body>
    
    <select onchange="getElementById('cb').style.display=this.value">
    <option value="none"> please select </option> 
    <option value="none"> company 1 </option>
    <option value="block"> company 2 </option>
    <option value="none"> company 3 </option>
    </select>
    <div id="cb"><input type="checkbox"/>Just this one?</div>
    
    </body>
    </html>

  3. #3
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265

    Exclamation

    Sort of like that, yes, but the options' values have to be the ID-numbers of the companies

  4. #4
    Join Date
    Nov 2010
    Posts
    1,097
    so like this then?

    Code:
    <!DOC HTML>
    <html>
    <head>
    <style>
    #cb {display:none}
    </style>
    </head>
    
    <body>
    
    <select onchange="checkId(this.value)">
    <option value="111"> please select </option> 
    <option value="222"> company 1 </option>
    <option value="666"> company 2 </option>
    <option value="333"> company 3 </option>
    </select>
    <div id="cb"><input type="checkbox"/>Just this one?</div>
    <script type="text/javascript">
    function checkId(val){
    document.getElementById("cb").style.display=val=="666"?"block":"none";
    }
    </script>
    </body>
    </html>

  5. #5
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265
    Yes, that should do the trick! I'll give it a shot. Thank you!

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434

    Lightbulb

    Alternative solution (because I'm such a slow typist!)
    Code:
    <!DOC HTML>
    <html>
    <head>
    <style>
    #cb {display:none}
    </style>
    <script type="text/javascript">
    //<![CDATA[
    function selectCompany(info) {
      var tarr = info.split(':');
      document.getElementById('cb').style.display=tarr[0];
      alert(tarr[1]);  // save or return value is necessary for later use elsewhere
    }
    //]]>
    </script>
    
    </head>
    
    <body>
    
    <select onchange="selectCompany(this.value)">
    <option value="none:"> please select </option> 
    <option value="none:Company 1">  company 1 </option>
    <option value="block:Company 2"> company 2 </option>
    <option value="none:Company 3">  company 3 </option>
    </select>
    <div id="cb"><input type="checkbox"/>Just this one?</div>
    
    </body>
    </html>

Thread Information

Users Browsing this Thread

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

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