##### H OME ##### inquiry.com Ask the Pros Ask the JavaScript Pro ##### A NSWERS ##### Q & A Ask a Question Microsoft's Knowledge Base ##### R ESOURCES ##### Search Discussion Section Useful Sites ##### A BOUT ##### Who is the Pro? Usage Policies |  | ### Q & A - Pulldown Menu Hyperlink
Applies to These Versions | Categories
--- | ---
Version Numbers Not Applicable | Basics Forms Hyperlinks
How can I put a hyperlink in the "Option" of a Pulldown Menu? If you mean you want to automatically go to a URL when the user selects an item from a SELECT control, then that's easy to do. Set the VALUE of each OPTION to the URL you'd like to go to when that option is selected. Then respond to the onChange event by setting the location of the top window (window.top.location.href) to the value of the selected item. The code below works in both Internet Explorer and Netscape:
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript">

    function selecturl(s) {
    	var gourl = s.options[s.selectedIndex].value;
    	window.top.location.href = gourl;
    }

    </SCRIPT>
    </HEAD>
    <BODY>

    <FORM>

    <SELECT NAME="urljump" OnChange="selecturl(this)">
    	<OPTION VALUE="http://www.devx.com">The Development Exchange</OPTION>
    	<OPTION VALUE="http://www.microsoft.com">Microsoft's Homepage</OPTION>
    	<OPTION VALUE="http://www.netscape.com">Netscape's Homepage</OPTION>
    </SELECT>

    </FORM>

    </BODY>
    </HTML>
See this code in action at http://www.inquiry.com/techtips/js_pro/files/selecturl.htm. Written by Boris Feldman on 6/8/98. Comments or problems with this site? Talk to us! Copyright © 1998 by Fawcette Technical Publications, Inc. All rights reserved.