Jump to content

Append a value to url?


chaking

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/93416-append-a-value-to-url/
Share on other sites

That would work too - Thanks  ;D

 

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 -

Link to comment
https://forums.phpfreaks.com/topic/93416-append-a-value-to-url/#findComment-478619
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.