Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting a item in drop down list

Status
Not open for further replies.

ishikha

Programmer
Mar 22, 2002
36
0
0
IN
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

ishikha



 
I have 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.



<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=&quot;form1&quot;>
<input type=&quot;button&quot; value=&quot;three&quot; onclick=&quot;select_item(document.form1.mySelect,'six');&quot;>
<select name=&quot;mySelect&quot;>
<option value=&quot;one&quot;>1</option>
<option value=&quot;two&quot;>2</option>
<option value=&quot;three&quot;>3</option>
<option value=&quot;four&quot;>4</option>
<option value=&quot;five&quot;>5</option>
<option value=&quot;six&quot;>6</option>
</select>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top