I have the following HTML code:
<select name="forma">
<option value="Home">Home</option>
<option value="Contact">Contact</option>
<option value="Sitemap">Sitemap</option>
</select>
How can I make Home, Contact and Sitemap values as links? I used the following code and as I expected it didn't work:
<select name="forma">
<option value="Home"><a href="home.php">Home</a></option>
<option value="Contact"><a href="contact.php">Contact</a></option>
<option value="Sitemap"><a href="sitemap.php">Sitemap</a></option>
</select>
The accepted solution looks good, but there is one case it cannot handle:
The "onchange" event will not be triggered when the same option is reselected. So, I came up with the following improvement:
HTML
jQuery
(I don't have enough reputation to comment on toscho's answer.)
I have no experience with screen readers and I'm sure your points are valid.
However as far as using a keyboard to manipulate selects, it is trivial to select any option by using the keyboard:
TAB to the control
SPACE to open the select list
UP or DOWN arrows to scroll to the desired list item
ENTER to select the desired item
Only on ENTER does the onchange or (JQuery .change()) event fire.
While I personally would not use a form control for simple menus, there are many web applications that use form controls to change the presentation of the page (eg., sort order.) These can be implemented either by AJAX to load new content into the page, or, in older implementations, by triggering new page loads, which is essentially a page link.
IMHO these are valid uses of a form control.
UPDATE (Nov 2015): In this day and age if you want to have a drop menu there are plenty of arguably better ways to implement one. This answer is a direct answer to a direct question, but I don't advocate this method for public facing web sites.
You cant use href tags withing option tags. You will need javascript to do so.
The
<select>
tag creates a dropdown list. You can't put html links inside a dropdown.However, there are JavaScript libraries that provide similar functionality. Here is one example: http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm
Try this Code