...

View Full Version : Selecting a select box by clicking a link



sagaticus
06-11-2007, 09:05 PM
Can someone help me use javascript to select an option from a select box by clicking a link?


<a href="#">option 1</a><br>
<a href="#">option 2</a><br>
<a href="#">option 3</a><br><br>

<SELECT name="form">
<OPTION value="" selected>Please select a subject</OPTION>
<OPTION value="">--------</OPTION>
<OPTION value=optone>Option One</OPTION>
<OPTION value=opttwo>Option Two</OPTION>
<OPTION value=optthree>Option Three</OPTION>
</SELECT>

So if you click the option three link, the select box will change. Thanks!

glenngv
06-11-2007, 10:54 PM
function selectOption(option){
document.frm.subject.value = option;
return false;
}

<form name="frm">
<a href="#" onclick="return selectOption('optone');">option 1</a><br>
<a href="#" onclick="return selectOption('opttwo');">option 2</a><br>
<a href="#" onclick="return selectOption('optthree');">option 3</a><br><br>

<SELECT name="subject">
<OPTION value="" selected>Please select a subject</OPTION>
<OPTION value="">--------</OPTION>
<OPTION value="optone">Option One</OPTION>
<OPTION value="opttwo">Option Two</OPTION>
<OPTION value="optthree">Option Three</OPTION>
</SELECT>
</form>

sagaticus
06-11-2007, 11:30 PM
Thank you very much Glenn. This is perfect!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum