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,716
    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>
    signature under construction

  2. #17
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    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>
    signature under construction

  3. #18
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    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
    signature under construction

  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,716
    you're welcome, greetings from Russia )
    signature under construction

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12649 seconds
  • Memory Usage 2,933KB
  • Queries Executed 15 (?)
More Information
Template Usage (37):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (74):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates