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

Reaching last option of select box

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
How can I reach the last option in select box using javascript,
WITHOUT the need of checking how many options I have?

Currently I use:

document.form1.selectName.selectedIndex=4;

Thanks
 
" WITHOUT the need of checking how many options I have?"

??? is it soooooooooooooooo hard to write :
document.form1.selectName.selectedIndex=document.form1.selectName.length ???????????
come on !
 
Thanks dear.
No it's not hard...WHEN u know WHAT to write
(which I didn't). :)

Anyway, I got two ways now:
One is yours (except it should be "length-1" instead of "length"):

document.form1.selectName.selectedIndex=document.form1.selectName.length-1

Second:

document.form1.selectName.selectedIndex=document.form1.selectName.options.length-1;

Thanks again.
 
i'm sorry for being ... rude ;-)
to me "checking how many options I have" was exactly the same as "document.form1.selectName.(options.)length" ! that's why i thought your question was weird ;] !
happy to know that it's working for you now :))
 
Yes, Sometimes u can't think simple when dealing
with complex stuff (Plus I was too lazy to check the syntax)
:)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top