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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select from a combobox 1

Status
Not open for further replies.

durug

Technical User
Mar 22, 2002
335
CA
Hi,

I have a combobox which is populated dynamicly when the page loads. Lets say it
<select name=&quot;Test&quot;>
<option selected value=&quot;A&quot;>A</option>
<option value=&quot;B&quot;>B</option>
<option value=&quot;C&quot;>C</option>
</select>

What I'm trying to accomplish: in the moment when I click a button the selected value form the combobox to be B not A anymore. So the combobox will show B not A.

Is there a way to do it through Javascript and not to reload the page?

Thanks a lot,
Durug

 
I think this is what you want:

document.formName.selectName.selectedIndex=1;

That will select the second one... You can change it to select whichever one you want.
 
<select ID=&quot;Test&quot; name=&quot;Test&quot;>


<script language=javascript>

function ChangeSelBox(pIndex){

//get the select box object
var objSel=document.getElementById(&quot;Test&quot;);

//select the option based on passed in parameter
objSel.options[pIndex].selected=true;

}
</script>

<button onclick='ChangeSelBox(1)'>Select Option 1</button>
<button onclick='ChangeSelBox(2)'>Select Option 2</button>

and so on...

*remember select boxes, options start at position (0) zero.

&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top