himani Posted June 4, 2008 Share Posted June 4, 2008 have created a dropdown box by fetching values of categories from mssql database. so can anybody help me in doing this-> if i select any option from drop down menu it should directly to that particular page and should display all the values under that category. for eg if i select category india it should display all the states in india Himani ??? Quote Link to comment https://forums.phpfreaks.com/topic/108650-drop-down-menu/ Share on other sites More sharing options...
hansford Posted June 4, 2008 Share Posted June 4, 2008 Javascript and ajax can do this without reloading or submitting the page-ie a redirect. How to do this-? well, you'll have to wait til tomorrow when I sober up hehe Quote Link to comment https://forums.phpfreaks.com/topic/108650-drop-down-menu/#findComment-557202 Share on other sites More sharing options...
hansford Posted June 4, 2008 Share Posted June 4, 2008 Well forget ajax - it's not needed here since you want to go directly to another page. This is a javascript example. The <option value='india' or whatever you want to call it would be the name of the page that contains the states ie: 'india'. The javascript function will add it's ending ie: '.php' or '.html' -------------------------------------- <html> <body> <?php echo "<form name='formcountries' method='post' action=''>"; echo "<select name='countries' onchange='getstates(this.form)'>"; echo "<option value='india'>India</option>"; echo "<option value='africa'>Africa</option>"; echo "<option value='america'>America</option>"; echo "</select></form>"; ?> <script language='javascript'> function getstates(frm){ var box = frm.countries; var value = box.options[box.selectedIndex].value; window.location.href= eval('"http://www.youraddress.com/' + value + '.php"'); } </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/108650-drop-down-menu/#findComment-557451 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.