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