www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: Show drop down menu options depending on checkbox clicked

  1. #16
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    it was not clear from your questions that you were using the post method in the form or i missed it. the same code with method="post":

    index.php

    Code:
    <?php
    header("Cache-Control: no-store");
    header("Expires: " . date("r"));
    header("Cache-Control: max-age=0");
    header("Cache-Control: no-cache");
    header("Expires: 0");
    header("Expires: Tue, 01 Jan 1970 1:00:00 GMT");
    header("Pragma: no-cache");
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Untitled </title>
    <style type="text/css">
    select {display:none;margin-top:5px;margin-bottom:5px;}
    </style>
    <script>
    var args=['1,2,5,6','2,3,4,5,6','1,2,6,12','1,2,3,4,5,6,11'];
    function $(id){return document.getElementById(id);}
    
    window.onload=function(){
    var i=0,
        loc=location.search.substr(1);
    while($('r'+i)!==null){
    $('r'+i).onclick=function(){
    var index=$('predef').value=this.id.substr(1),
        arr=args[index].split(','),
        sel=$('selectBoxes').getElementsByTagName('select');
    for(var k=0; k<sel.length; k++){sel[k].style.display='none';}
    for(var s=0; s<arr.length; s++){
    var sbox=Number(arr[s])-1;
    $('SB'+sbox).style.display='block';
    }
    }
    i++;
    }
    
    $('frm').onreset=function(){$('predef').value='';}
    //var preval=loc.split('&')[0].split('=')[1];
    //if($('r'+preval)!==null){$('r'+preval).click();}
    <?php
    if(isset($_POST['predef'])){
    echo '$("r'.$_POST['predef'].'").click();
    ';
    }
    ?>
    }
    </script>
    </head>
    <body>
    <form name="frm" id="frm" action="" method="post">
    <input type="hidden" name="predef" id="predef" />
    <input type="radio" name="Rbtn" id="r0" /> Items 1,2,5,6 <br />
    <input type="radio" name="Rbtn" id="r1" /> Items 2,3,4,5,6 <br />
    <input type="radio" name="Rbtn" id="r2" /> Items 1,2,6,12 <br />
    <input type="radio" name="Rbtn" id="r3" /> Items 1,2,3,4,5,6,11 <br />
    <p>
    <div id="selectBoxes">
    <select id="SB0">  <option>SB00</option> <option>SB01</option> <option>SB02</option> </select>
    <select id="SB1">  <option>SB10</option> <option>SB11</option> <option>SB12</option> </select>
    <select id="SB2">  <option>SB20</option> <option>SB21</option> <option>SB22</option> </select>
    <select id="SB3">  <option>SB30</option> <option>SB31</option> <option>SB32</option> </select>
    <select id="SB4">  <option>SB40</option> <option>SB41</option> <option>SB42</option> </select>
    <select id="SB5">  <option>SB50</option> <option>SB51</option> <option>SB52</option> </select>
    <select id="SB6">  <option>SB60</option> <option>SB61</option> <option>SB62</option> </select>
    <select id="SB7">  <option>SB70</option> <option>SB71</option> <option>SB72</option> </select>
    <select id="SB8">  <option>SB80</option> <option>SB81</option> <option>SB82</option> </select>
    <select id="SB9">  <option>SB90</option> <option>SB91</option> <option>SB92</option> </select>
    <select id="SB10"> <option>SBA0</option> <option>SBA1</option> <option>SBA2</option> </select>
    <select id="SB11"> <option>SBB0</option> <option>SBB1</option> <option>SBB2</option> </select>
    </div>
    <div><input type="submit" value="Submit" />&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" /></div>
    </form>
    </body>
    </html>

  2. #17
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    this php condition works better

    Code:
    <?php
    header("Cache-Control: no-store");
    header("Expires: " . date("r"));
    header("Cache-Control: max-age=0");
    header("Cache-Control: no-cache");
    header("Expires: 0");
    header("Expires: Tue, 01 Jan 1970 1:00:00 GMT");
    header("Pragma: no-cache");
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Untitled </title>
    <style type="text/css">
    select {display:none;margin-top:5px;margin-bottom:5px;}
    </style>
    <script>
    var args=['1,2,5,6','2,3,4,5,6','1,2,6,12','1,2,3,4,5,6,11'];
    function $(id){return document.getElementById(id);}
    
    window.onload=function(){
    var i=0,
        loc=location.search.substr(1);
    while($('r'+i)!==null){
    $('r'+i).onclick=function(){
    var index=$('predef').value=this.id.substr(1),
        arr=args[index].split(','),
        sel=$('selectBoxes').getElementsByTagName('select');
    for(var k=0; k<sel.length; k++){sel[k].style.display='none';}
    for(var s=0; s<arr.length; s++){
    var sbox=Number(arr[s])-1;
    $('SB'+sbox).style.display='block';
    }
    }
    i++;
    }
    
    $('frm').onreset=function(){$('predef').value='';}
    //var preval=loc.split('&')[0].split('=')[1];
    //if($('r'+preval)!==null){$('r'+preval).click();}
    <?php
    if(!empty($_POST['predef'])||$_POST['predef']==='0'){
    echo '$("r'.$_POST['predef'].'").click();
    ';
    }
    ?>
    }
    </script>
    </head>
    <body>
    <form name="frm" id="frm" action="" method="post">
    <input type="hidden" name="predef" id="predef" />
    <input type="radio" name="Rbtn" id="r0" /> Items 1,2,5,6 <br />
    <input type="radio" name="Rbtn" id="r1" /> Items 2,3,4,5,6 <br />
    <input type="radio" name="Rbtn" id="r2" /> Items 1,2,6,12 <br />
    <input type="radio" name="Rbtn" id="r3" /> Items 1,2,3,4,5,6,11 <br />
    <p>
    <div id="selectBoxes">
    <select id="SB0">  <option>SB00</option> <option>SB01</option> <option>SB02</option> </select>
    <select id="SB1">  <option>SB10</option> <option>SB11</option> <option>SB12</option> </select>
    <select id="SB2">  <option>SB20</option> <option>SB21</option> <option>SB22</option> </select>
    <select id="SB3">  <option>SB30</option> <option>SB31</option> <option>SB32</option> </select>
    <select id="SB4">  <option>SB40</option> <option>SB41</option> <option>SB42</option> </select>
    <select id="SB5">  <option>SB50</option> <option>SB51</option> <option>SB52</option> </select>
    <select id="SB6">  <option>SB60</option> <option>SB61</option> <option>SB62</option> </select>
    <select id="SB7">  <option>SB70</option> <option>SB71</option> <option>SB72</option> </select>
    <select id="SB8">  <option>SB80</option> <option>SB81</option> <option>SB82</option> </select>
    <select id="SB9">  <option>SB90</option> <option>SB91</option> <option>SB92</option> </select>
    <select id="SB10"> <option>SBA0</option> <option>SBA1</option> <option>SBA2</option> </select>
    <select id="SB11"> <option>SBB0</option> <option>SBB1</option> <option>SBB2</option> </select>
    </div>
    <div><input type="submit" value="Submit" />&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" /></div>
    </form>
    </body>
    </html>

  3. #18
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    updated lightly changed code

    Code:
    <?php
    header("Cache-Control: no-store");
    header("Expires: " . date("r"));
    header("Cache-Control: max-age=0");
    header("Cache-Control: no-cache");
    header("Expires: 0");
    header("Expires: Tue, 01 Jan 1970 1:00:00 GMT");
    header("Pragma: no-cache");
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Untitled </title>
    <style type="text/css">
    input{cursor:pointer;}
    #result{position:absolute;top:10px;right:10px;padding:20px;border:2px solid #ccc;border-radius:10px;color:#000;background-color:#f2f5da;}
    select {display:none;margin-top:5px;margin-bottom:5px;}
    </style>
    <script>
    var args=['1,2,5,6','2,3,4,5,6','1,2,6,12','1,2,3,4,5,6,11'];
    function $(id){return document.getElementById(id);}
    
    window.onload=function(){
    var i=0,
        sel=$('selectBoxes').getElementsByTagName('select');
    	
    for(var n=0; n<sel.length; n++){
    var opts=sel[n].options;
    /*
    adding the "value" attribute to every option element
    according to its "text" value
    */
    for(var z=0; z<opts.length; z++){
    opts[z].value=opts[z].text;
    }
    /*
    adding the first option with empty value 
    to every select element
    and focusing on this option
    */
    sel[n].options[0]=new Option('select','');
    sel[n].selectedIndex=0;
    /*
    adding the "name" attribute to every select element
    according to its "id" attribute value
    */
    sel[n].name=sel[n].id;
    }
    	
    while($('r'+i)!==null){
    $('r'+i).onclick=function(){
    var index=$('predef').value=this.id.substr(1),
        arr=args[index].split(',');
    for(var k=0; k<sel.length; k++){sel[k].style.display='none';}
    for(var s=0; s<arr.length; s++){
    var sbox=Number(arr[s])-1;
    $('SB'+sbox).style.display='block';
    }
    }
    i++;
    }
    
    $('frm').onreset=function(){
    $('predef').value='';
    try{document.body.removeChild($('result'));}
    catch(e){}
    }
    <?php
    if(!empty($_POST['predef'])||$_POST['predef']==='0'){
    echo '$("r'.$_POST['predef'].'").click();
    ';
    }
    ?>
    }
    </script>
    </head>
    <body>
    <form name="frm" id="frm" action="" method="post">
    <input type="hidden" name="predef" id="predef" value="" />
    <input type="radio" name="Rbtn" id="r0" /> Items 1,2,5,6 <br />
    <input type="radio" name="Rbtn" id="r1" /> Items 2,3,4,5,6 <br />
    <input type="radio" name="Rbtn" id="r2" /> Items 1,2,6,12 <br />
    <input type="radio" name="Rbtn" id="r3" /> Items 1,2,3,4,5,6,11 <br />
    <p>
    <div id="selectBoxes">
    <select id="SB0">  <option>SB00</option> <option>SB00</option> <option>SB01</option> <option>SB02</option> </select>
    <select id="SB1">  <option>SB10</option> <option>SB11</option> <option>SB12</option> </select>
    <select id="SB2">  <option>SB20</option> <option>SB21</option> <option>SB22</option> </select>
    <select id="SB3">  <option>SB30</option> <option>SB31</option> <option>SB32</option> </select>
    <select id="SB4">  <option>SB40</option> <option>SB41</option> <option>SB42</option> </select>
    <select id="SB5">  <option>SB50</option> <option>SB51</option> <option>SB52</option> </select>
    <select id="SB6">  <option>SB60</option> <option>SB61</option> <option>SB62</option> </select>
    <select id="SB7">  <option>SB70</option> <option>SB71</option> <option>SB72</option> </select>
    <select id="SB8">  <option>SB80</option> <option>SB81</option> <option>SB82</option> </select>
    <select id="SB9">  <option>SB90</option> <option>SB91</option> <option>SB92</option> </select>
    <select id="SB10"> <option>SBA0</option> <option>SBA1</option> <option>SBA2</option> </select>
    <select id="SB11"> <option>SBB0</option> <option>SBB1</option> <option>SBB2</option> </select>
    </div>
    <div><input type="submit" value="Submit" />&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" /></div>
    </form>
    <?php
    if(count($_POST)!==0&&$_POST['predef']!==''){
    $output='<center><h2>The following <span style="color:Crimson">$_POST</span> values has just been recieved:</h2><br />';
    foreach($_POST as $key => $val){
    $output.='<i>'.$key.'</i> = <b>'.( ($val!=='')?$val:'<span style="color:#ccc">this element has not been changed/selected</span>' ).'</b><br />';
    }
    echo '<div id="result">'.$output.'</center></div>';
    }
    ?>
    </body>
    </html>
    and live demo

  4. #19
    Join Date
    Dec 2009
    Posts
    51

    Red face

    Quote Originally Posted by Padonak View Post
    updated lightly changed code

    Code:
    <?php
    header("Cache-Control: no-store");
    header("Expires: " . date("r"));
    header("Cache-Control: max-age=0");
    header("Cache-Control: no-cache");
    header("Expires: 0");
    header("Expires: Tue, 01 Jan 1970 1:00:00 GMT");
    header("Pragma: no-cache");
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <title> Untitled </title>
    <style type="text/css">
    input{cursor:pointer;}
    #result{position:absolute;top:10px;right:10px;padding:20px;border:2px solid #ccc;border-radius:10px;color:#000;background-color:#f2f5da;}
    select {display:none;margin-top:5px;margin-bottom:5px;}
    </style>
    <script>
    var args=['1,2,5,6','2,3,4,5,6','1,2,6,12','1,2,3,4,5,6,11'];
    function $(id){return document.getElementById(id);}
    
    window.onload=function(){
    var i=0,
        sel=$('selectBoxes').getElementsByTagName('select');
    	
    for(var n=0; n<sel.length; n++){
    var opts=sel[n].options;
    /*
    adding the "value" attribute to every option element
    according to its "text" value
    */
    for(var z=0; z<opts.length; z++){
    opts[z].value=opts[z].text;
    }
    /*
    adding the first option with empty value 
    to every select element
    and focusing on this option
    */
    sel[n].options[0]=new Option('select','');
    sel[n].selectedIndex=0;
    /*
    adding the "name" attribute to every select element
    according to its "id" attribute value
    */
    sel[n].name=sel[n].id;
    }
    	
    while($('r'+i)!==null){
    $('r'+i).onclick=function(){
    var index=$('predef').value=this.id.substr(1),
        arr=args[index].split(',');
    for(var k=0; k<sel.length; k++){sel[k].style.display='none';}
    for(var s=0; s<arr.length; s++){
    var sbox=Number(arr[s])-1;
    $('SB'+sbox).style.display='block';
    }
    }
    i++;
    }
    
    $('frm').onreset=function(){
    $('predef').value='';
    try{document.body.removeChild($('result'));}
    catch(e){}
    }
    <?php
    if(!empty($_POST['predef'])||$_POST['predef']==='0'){
    echo '$("r'.$_POST['predef'].'").click();
    ';
    }
    ?>
    }
    </script>
    </head>
    <body>
    <form name="frm" id="frm" action="" method="post">
    <input type="hidden" name="predef" id="predef" value="" />
    <input type="radio" name="Rbtn" id="r0" /> Items 1,2,5,6 <br />
    <input type="radio" name="Rbtn" id="r1" /> Items 2,3,4,5,6 <br />
    <input type="radio" name="Rbtn" id="r2" /> Items 1,2,6,12 <br />
    <input type="radio" name="Rbtn" id="r3" /> Items 1,2,3,4,5,6,11 <br />
    <p>
    <div id="selectBoxes">
    <select id="SB0">  <option>SB00</option> <option>SB00</option> <option>SB01</option> <option>SB02</option> </select>
    <select id="SB1">  <option>SB10</option> <option>SB11</option> <option>SB12</option> </select>
    <select id="SB2">  <option>SB20</option> <option>SB21</option> <option>SB22</option> </select>
    <select id="SB3">  <option>SB30</option> <option>SB31</option> <option>SB32</option> </select>
    <select id="SB4">  <option>SB40</option> <option>SB41</option> <option>SB42</option> </select>
    <select id="SB5">  <option>SB50</option> <option>SB51</option> <option>SB52</option> </select>
    <select id="SB6">  <option>SB60</option> <option>SB61</option> <option>SB62</option> </select>
    <select id="SB7">  <option>SB70</option> <option>SB71</option> <option>SB72</option> </select>
    <select id="SB8">  <option>SB80</option> <option>SB81</option> <option>SB82</option> </select>
    <select id="SB9">  <option>SB90</option> <option>SB91</option> <option>SB92</option> </select>
    <select id="SB10"> <option>SBA0</option> <option>SBA1</option> <option>SBA2</option> </select>
    <select id="SB11"> <option>SBB0</option> <option>SBB1</option> <option>SBB2</option> </select>
    </div>
    <div><input type="submit" value="Submit" />&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" /></div>
    </form>
    <?php
    if(count($_POST)!==0&&$_POST['predef']!==''){
    $output='<center><h2>The following <span style="color:Crimson">$_POST</span> values has just been recieved:</h2><br />';
    foreach($_POST as $key => $val){
    $output.='<i>'.$key.'</i> = <b>'.( ($val!=='')?$val:'<span style="color:#ccc">this element has not been changed/selected</span>' ).'</b><br />';
    }
    echo '<div id="result">'.$output.'</center></div>';
    }
    ?>
    </body>
    </html>
    and live demo


    Wow many thanks Padonak!!!

  5. #20
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    you're welcome, greetings from Russia )

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