cip6791 Posted August 10, 2010 Share Posted August 10, 2010 Hello, I'm trying to use a dropdown to display different divs. <html> <head> <title>DDlist Div Display</title> <script type="text/javascript"> function ShowDivArea(info) { var sel = document.getElementById('divArea').getElementsByTagName('div'); for (var i=0; i<sel.length; i++) { sel.style.display = 'none'; } if (info == '0') { return; } document.getElementById('divArea'+info).style.display = 'block'; } </script> <style type="text/css"> .divArea { display:none; height:100px; width:200px; border:1px solid red; } </style> </head> <body> <select id="DDDivList" onchange="ShowDivArea(this.selectedIndex)"> <option value="0" selected> -- Select A Design Service --</option> <option value="1"> QR Bookmark </option> <option value="2"> Twitter </option> <option value="3"> Ning or Tumblr </option> <option value="4"> Flyers </option> <option value="5"> Business Card or Brochure</option> <option value="6"> Album or Mixtape cover</option> <option value="7"> Other</option> </select> <div id="divArea"> <div id="divArea1" class="divArea"> <h1>QR Bookmarks</h1> <form action='qrgen.php' method='POST'> <input type='text' name='bmarksite'> URL<br> <input type='text' name='sitedesc'> Description<br> <input type='submit' value='Convert'><br> <?php include("QrCodes.php") ?> <?php $bmarksite = $_POST['bmarksite']; $sitedesc = $_POST['sitedesc']; if ($sitedesc&&$bmarksite) { $qrcode = new QrCodes; $qrcode -> IsImage =1; echo $qrcode -> GetBookmark("$bmarksite","$sitedesc"); echo "</br>"; echo $bmarksite; echo "</br>"; print $sitedesc; } else { echo "Please fill in all the required fields."; } ?> </div> <div id="divArea2" class="divArea">Twitter</div> <div id="divArea3" class="divArea">Ning or Tumblr</div> <div id="divArea4" class="divArea">Flyers</div> <div id="divArea5" class="divArea">Business Card or Brochure</div> <div id="divArea6" class="divArea">Album or Mixtape Cover</div> <div id="divArea7" class="divArea">Other</div> </div> </body> </html> The problem is with this line: <form action='qrgen.php' method='POST'>. I am using a wordpress page template. What should I change the qrgen.php to? Or how do I get it to work? Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/210383-drop-down-with-php/ Share on other sites More sharing options...
Lucky2710 Posted August 11, 2010 Share Posted August 11, 2010 I'm working on a similar problem. I found this http://bytes.com/topic/javascript/answers/88791-show-hide-text-form-field-based-drop-down-selection Look at the reply that Mrk put. His is done with tables but you can easily put your divs in the tables. In order to do what your trying to do you need javascript Like i said though i'm doing the exact same thing right now so if you go with this and get stuck let me know i've almost got it working how i need it too. Quote Link to comment https://forums.phpfreaks.com/topic/210383-drop-down-with-php/#findComment-1097856 Share on other sites More sharing options...
Lucky2710 Posted August 11, 2010 Share Posted August 11, 2010 Heads up if you use the script i linked to earlier. You CAN NOT put a table inside the table. Idk why but it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/210383-drop-down-with-php/#findComment-1097901 Share on other sites More sharing options...
Lucky2710 Posted August 11, 2010 Share Posted August 11, 2010 Never-mind yes you can! Quote Link to comment https://forums.phpfreaks.com/topic/210383-drop-down-with-php/#findComment-1097902 Share on other sites More sharing options...
cip6791 Posted August 11, 2010 Author Share Posted August 11, 2010 Any luck? I m still having the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/210383-drop-down-with-php/#findComment-1097930 Share on other sites More sharing options...
Lucky2710 Posted August 11, 2010 Share Posted August 11, 2010 Ya i got it working. Heres a working code for 7 divs. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Show/Hide</title> <script type="text/javascript"> // <![CDATA[ function display(obj,id1,id2,id3,id4,id5,id6,id7) { txt = obj.options[obj.selectedIndex].value; document.getElementById(id1).style.display = 'none'; document.getElementById(id2).style.display = 'none'; document.getElementById(id3).style.display = 'none'; document.getElementById(id4).style.display = 'none'; document.getElementById(id5).style.display = 'none'; document.getElementById(id6).style.display = 'none'; document.getElementById(id7).style.display = 'none'; if ( txt.match(id1) ) { document.getElementById(id1).style.display = 'block'; } if ( txt.match(id2) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id3) ) { document.getElementById(id3).style.display = 'block'; } if ( txt.match(id4) ) { document.getElementById(id4).style.display = 'block'; } if ( txt.match(id5) ) { document.getElementById(id5).style.display = 'block'; } if ( txt.match(id6) ) { document.getElementById(id6).style.display = 'block'; } if ( txt.match(id7) ) { document.getElementById(id7).style.display = 'block'; } } // ]]> </script> </head> <body> <table width="500" cellspacing="0" cellpadding="0"> <thead> <tr> <td width="303" class="title">Select a Design Service</td> <td width="195" class="field"> <select name="type" onChange="display(this,'1','2','3','4','5','6','7');"> <option value="s" selected>Please Select...</option> <option value="1">QR Bookmaek</option> <option value="2">Twitter</option> <option value="3">Ning or Tumblr</option> <option value="4">Flyers</option> <option value="5">Business Cards or Brochure</option> <option value="6">Album or Mixtape Cover</option> <option value="7">Other</option> </select> </td> </tr> </thead> <tfoot> </tfoot> <tbody id="1" style="display: none;"> <tr><td><br> <div>1</div> </td></tr> </tbody> <tbody id="2" style="display: none;"> <tr><td><br> <div>2</div> </td></tr> </tbody> <tbody id="3" style="display: none;"> <tr><td><br> <div>3</div> </td></tr> </tbody> <tbody id="4" style="display: none;"> <tr><td><br> <div>4</div> </td></tr> </tbody> <tbody id="5" style="display: none;"> <tr><td><br> <div>5</div> </td></tr> </tbody> <tbody id="6" style="display: none;"> <tr><td><br> <div>6</div> </td></tr> </tbody> <tbody id="7" style="display: none;"> <tr><td><br> <div>7</div> </td></tr> </tbody> <tbody> </tbody> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/210383-drop-down-with-php/#findComment-1098090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.