Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q1025 How can I pass the value of the selected option to the next page as part of the HREF property of a text link?

You are here: irt.org | FAQ | JavaScript | Link | Q1025 [ previous next ]

Use the following:

<SCRIPT LANGUAGE="JavaScript"><!--
function getValue(url) {
    return (url.indexOf('?') > -1 ? url.substring(0,url.indexOf('?')) : url) +
           '?' + escape(document.myName.mySelect.options[document.myName.mySelect.selectedIndex].value);

<FORM NAME="myName">
<SELECT NAMe="mySelect">
<OPTION VALUE="123">first
<OPTION VALUE="234">second
<OPTION VALUE="345">third

<A HREF="http://www.irt.org/" onClick="this.href=getValue(this.href)">irt.org</A>

©2018 Martin Webb