PDA

View Full Version : selecting a item in drop down list


shikha
05-05-2003, 12:24 PM
hi friends,

i want to select the particular item in the drop down list corresponding to the string sent by clicking on some button.
suppose when i click on check button it sents the string "abc" to the function which then select the item in the drop down list having value "abc" in javascript

thanx in advance

shikha

x_goose_x
05-05-2003, 12:51 PM
<html>
<head>
<script>
function select_item( selc, item) {
for ( x=0; x<selc.options.length; x++) {
if (selc.options[x].value == item ) {
selc.options[x].selected = true;
return;
}
}
}
</script>
</head>

<body>
<form name="form1">
<input type="button" value="three" onclick="select_item(document.form1.mySelect,'six');">
<select name="mySelect">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
<option value="four">4</option>
<option value="five">5</option>
<option value="six">6</option>
</select>
</form>
</body>
</html>


If there are two options witht the same value, it will select the first.

shikha
05-05-2003, 12:56 PM
I also done by this way.but is there any other way by which i can do this.actually i have to implement this logic in jsp and if i use this code then it is difficult to implement this code in jsp.

i want some simpler way.

shikha

Skyzyx
05-05-2003, 04:13 PM
Looking at the code, that's about as simple as it gets... sorry.