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

Drop down boxes

Status
Not open for further replies.

sucram

Programmer
May 23, 2001
75
GB
Hi

Can JavaScript be used to change the selected value in a drop down box on a webpage??

Thanks,
Marcus
 
Yes.

<script>
function changeSelect(){
curIndex = document.myForm.mySelect.selectedIndex
if (curIndex < document.myForm.mySelect.options.length - 1){
document.myForm.mySelect.selectedIndex = curIndex++
}
}
</script>

<form name=&quot;myForm&quot;>
<select name=&quot;mySelect&quot;>
<option selected>1
<option>2
<option>3
<option>4
<option>5
</select>
<input value=&quot;Click&quot; onClick=&quot;changeSelect()&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
ooppss that last line should be...

<input type=button value=&quot;Click&quot; onClick=&quot;changeSelect()&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Thanks for the help guys, much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top