View Full Version : Selecting a form list item with JS link

05-03-2006, 05:24 PM
I've got a list/menu item in a search form ...

<select name="ccode" id=ccode >
<option value=0>World</option>
<OPTION VALUE="1" >Afghanistan</OPTION>
<OPTION VALUE="4" >American Samoa</OPTION>
etc, etc.

Since this list include every country in the world (a long list) I'd like to offer users the a few text links along the side that select popular countries within the list without having to scroll through the huge list ... click here to select United States, click here to select Japan, etc.

How would I do this with JS? I appreciate any guidance.



05-03-2006, 05:39 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function selectOpt(what)
document.forms[0].ccode.options[what].selected = true;

<a href="#" onclick="selectOpt(3);return false">Select Algeria</a><br>
<a href="#" onclick="selectOpt(1);return false">Select Afghanistan</a><br>
<a href="#" onclick="selectOpt(5);return false">Select Andorra</a><br>
<form action="#">
<select name="ccode" id="ccode" >
<option value="0">World</option>
<option value="1" >Afghanistan</option>
<option value="2" >Albania</option>
<option value="3" >Algeria</option>
<option value="4" >American Samoa</option>
<option value="5" >Andorra</option>

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum