...

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



sanfranjr
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="2" >Albania</OPTION>
<OPTION VALUE="3" >Algeria</OPTION>
<OPTION VALUE="4" >American Samoa</OPTION>
<OPTION VALUE="5" >Andorra</OPTION>
etc, etc.
</select>

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.

Thanks!

J.R.

_Aerospace_Eng_
05-03-2006, 05:39 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<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;
}
</script>
</head>

<body>
<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>
</select>
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum