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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.