...

View Full Version : writing a function to select an option in a select dropdown list based on the label



chauzer
10-16-2005, 12:19 AM
i have a select dropdown list, with 4 options like this..



<select name="riskstrategytype">
<option value="">
<option value="1">Business
<option value="2">Final
<option value="3">Technical
</select>


then say inside a cell in a table i have something like this:



<td id="selectedType">
Final
</td>


is there a way where when i click a link/button have the select dropdown menu select whatever was in the cell?

here's the example:

www.chauzer.com/test/test.html

i want it so that when they click on "The Title" link, in the drop down menu above it'll select "Final" because it says Final in the 2nd row/2nd col

thanks

pccode
10-16-2005, 08:04 AM
This should do the trick:



<html>
<head>
<script>
function change() {
document.formname.riskstrategytype[2].selected = true;
}
</script>
</head>
<body>
<form name="formname">
<select name="riskstrategytype">
<option value="0" selected>
<option value="1">Business
<option value="2">Final
<option value="3">Technical
</select>
<input type="reset" value="reset">
</form>
<br><br>
<a href="javascript:change();">Final</a>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum