/    Sign up×
Community /Pin to ProfileBookmark

select form links

How do I make an <option> element–within a select form–activate a link when it is clicked? If this doesn’t make sense, please tell me and I will do my best to elaborate.

HTML: (This doesn’t work. Neither does <option value=”http://www.yoyo.com“>

<select>
<option><a href=”http://yoyo.com”>yoyo</a></option>
</select>

to post a comment
HTML

9 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 20.2010 — Would only work with JavaScript using the onchange in select.
Copy linkTweet thisAlerts:
@CharlesJan 20.2010 — &lt;form [b]action="javascript-free-fallback.php"[/b] onchange="window.location = this.options[this.seletedIndex].text; return false"&gt;
Copy linkTweet thisAlerts:
@bradleybebadauthorJan 20.2010 — OK, thanks!!! I guess I will do a css dropdown menu instead. Don't want all those peeps out there who don't have js enabled to be like, "WTF??" Thanks for the helps guys...
Copy linkTweet thisAlerts:
@CharlesJan 20.2010 — Just provide a wee, little, server side script that sends a redirect to the value passed by the form.
Copy linkTweet thisAlerts:
@bradleybebadauthorJan 20.2010 — When you say a "redirect script," do you mean something like this?

links.php page:

<?php

$link = $_GET['link'];

switch($link) {

case 1:

header('Location:http://www.yoyo.com');">http://www.yoyo.com');

break;

case 2:
header('Location:http://www.yoyo2.com');
break;


}

?>

HTML PAGE:

<form>

<select>

<option value="links.php?link=1">yoyo</option>

<option value="links.php?link=2">yoyo2</option>

</select>

</form>

I know this doesn't work, but how could I get it to direct to the php page that redirects the location?
Copy linkTweet thisAlerts:
@FangJan 20.2010 — &lt;?php
if(isset($_POST['link'])) {
switch($_POST['link']) {
case '1':
header('Location:http://www.yoyo.com');
exit;
case '2':
header('Location:http://www.yoyo2.com');
exit;
}
}
?&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;form action="" method="post"&gt;
&lt;div&gt;
&lt;select name="link" onchange="window.location = this.options[this.seletedIndex].text; return false"&gt;
&lt;option value=""&gt;select -&lt;/option&gt;
&lt;option value="1"&gt;http://www.yoyo.com&lt;/option&gt;
&lt;option value="2"&gt;http://www.yoyo2.com&lt;/option&gt;
&lt;/select&gt;
&lt;button type="submit"&gt;submit&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@bradleybebadauthorJan 20.2010 — Fang, you came to my rescue once again! Thanks for all the help everyone. You guys/girls really help me through some rough areas.
Copy linkTweet thisAlerts:
@bradleybebadauthorJan 27.2010 — Were you able to get this working Fang? I tried and failed
Copy linkTweet thisAlerts:
@FangJan 27.2010 — Post #7 works
×

Success!

Help @bradleybebad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...