chaking Posted February 27, 2008 Share Posted February 27, 2008 I'm trying to create a drop down menu from a table that when submitted will put the value on the end of a url and then go to that url. So, the drop down menu would have values like = pac,blr,hyd etc.. Those values need to be put on the end of ex: http:/xxx.com/index2.php?bldg="VALUE" I have built the query to grab the values, and I have the values inserted into a drop down list, but I don't know how to go to a url like I described on submit? Any help would be appreciated - This is what I have so far: function drop_down(){ include "cxn.php"; $cxn = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $list_one = "SELECT facility_code FROM facilities ORDER BY facility_code"; $list = mysqli_query($cxn, $list_one) or print(mysqli_error()); while($row_list = mysqli_fetch_assoc($list)){ echo "<option name=\"bldg\" value=\"$row_list[facility_code]\">$row_list[facility_code]</option>\n"; } echo "</select>\n\n"; } And then the form: <p>Select Facility:<br> <form> <select name="bldg" > <option value="NONE">Select Facility</option> <?php drop_down(); ?></p> <input type="button" value="Submit"> </form> Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 27, 2008 Share Posted February 27, 2008 header('Location: '.$url); If you're doing it after the page has loaded you'll need to use javascript, but that's not the best idea. Quote Link to comment Share on other sites More sharing options...
chaking Posted February 27, 2008 Author Share Posted February 27, 2008 That would work too - Thanks I did find the javascript solution though. Why should I not use javascript? Because of usability reasons only? (i.e. some people might not have js enabled?) here it is: Throw this in the file: <script type="text/javascript"> function nav() { var w = document.bldg_form.bldg_list.selectedIndex; var url_add = document.bldg_form.bldg_list.options[w].value; window.location.href = url_add; } </script> Then the function: <?php function drop_down(){ include "cxn.php"; $cxn = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $list_one = "SELECT facility_code FROM facilities ORDER BY facility_code"; $list = mysqli_query($cxn, $list_one) or print(mysqli_error()); while($row_list = mysqli_fetch_assoc($list)){ echo "<option name=\"bldg\" value=\"../../index2.php?bldg=$row_list[facility_code]\">$row_list[facility_code]</option>\n"; } echo "</select>\n\n"; } ?> Then the form: <form name="bldg_form"> <p>Jump To Facility:<br> <select name="bldg_list" onChange="nav()"> <option value="NONE">Select Facility</option> <?php drop_down(); ?></p> </select> </form> This takes the value you select and directs you to it immediately - Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 27, 2008 Share Posted February 27, 2008 good idear but it floored ur using javascript say javasript is off Quote Link to comment Share on other sites More sharing options...
chaking Posted February 28, 2008 Author Share Posted February 28, 2008 Yeah good point - It's alright though because this is not on a public server and I know who will be using it (so no worries about javascript) - Thanks Quote Link to comment 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.