By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Selecting and item in a dropdown box

P: 5
Let's assume I have a website with a dropdown box on it. there are 3 items in it;

1 - red
2 - blue
3 - green

Is there a javascript function that I could run make the selected item change to a certain item?


not sure if it's possible and I'm really sure these don't work, just don't know the syntax well enough to make it go. I believe the underlined portions are definitely wrong... can someone help?
Jan 31 '08 #1
Share this Question
Share on Google+
6 Replies

Death Slaught
P: 1,137
Yeah go here.

^_^ Hope it helps, Thanks, Death
Jan 31 '08 #2

P: 5
well i read through that link and i'm not sure what to use. It seems that is instructions for how to code a page. I want a bookmarklet that I can paste into my address bar that will change which item is in the dropdown box. The linked page says that the user needs to input. I want to automate that input. Is that possible?

also would it be possible to do this by form/element/desired option number?
Jan 31 '08 #3

Death Slaught
P: 1,137
I think you can automate it, but i'm not sure how.

I though you wanted to be able to erase an option and then replace it with something else. Sense that's not it I can't really help you much, someone will though.

^_^ Thanks, Death
Jan 31 '08 #4

Expert Mod 15k+
P: 16,027
You're looking for the selectedIndex property. Set that to the index of the select box - starting from 0.
Feb 1 '08 #5

P: 5

neither work... it's close to the right code but it doesn't work.
BTW i need a bookmarklet (able to paste it in the address bar, hit enter and see the change happen.

thanks for any input you may have!
Feb 1 '08 #6

Expert Mod 15k+
P: 16,027
That would be:
Expand|Select|Wrap|Line Numbers
  1. javascript:document.forms[0].elements[0].selectedIndex=0
Note the case - JavaScript is case-sensitive.
Feb 2 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.