Jump to content

Drop-down box link


solidrichard

Recommended Posts

hi ,

I have drop down box

$sql= "select * from table where nabor='1'" ;
$vysledek=mysql_query($sql); 

$moznosti=""; 

while ($row=mysql_fetch_array($vysledek)) { 

    $id=$row["id"]; 
    $projekt=$row["projekt"]; 
    $moznosti.="<OPTION VALUE=\"$id\">".$projekt;

	<SELECT NAME=projekt> 
<OPTION VALUE=0>Vyberte 
<?=$moznosti?> 
</SELECT> 

 

And I want if someone select project with for example id=5 link to another website...

Thanks for any answers

Link to comment
https://forums.phpfreaks.com/topic/236455-drop-down-box-link/
Share on other sites

You want it to redirect them to another site? Well then you'd need a bit of JavaScript, not PHP.

 

<select name="projekt" onchange="javascript: window.location=this.options[this.options.selectedIndex].value">

 

Then you can set the value to the location of each site, example:

$moznosti .= '<option value="http://examplesite.com/something.php?id=' . $id . '">' . $projekt . '</option>';

 

Going on memory here, not tested. Good luck.

Link to comment
https://forums.phpfreaks.com/topic/236455-drop-down-box-link/#findComment-1215652
Share on other sites

Be aware though that this does rely on the user having JavaScript enabled. Majority do these days, not sure how common it is for it to be disabled. But just be aware of that fact. Glad it worked. Hit the solved, bottom left of page, if you don't mind. :)

Link to comment
https://forums.phpfreaks.com/topic/236455-drop-down-box-link/#findComment-1215660
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.