wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes Using Javascript to Select an Item in a Select List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Using Javascript to Select an Item in a Select List" Watch "Using Javascript to Select an Item in a Select List" New topic
Author

Using Javascript to Select an Item in a Select List

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
Thsi causes an error. Please help with correct syntax.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you want to select an item, you need to just set the selected index



The code you showed in your above post is how you would get the option reference that is selected so you could get the text or value or set the option with new Option.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
When I run this code the alert will produce -1 eventhough projindex = 201

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
That the index value or the value of the element, I am guessing the value.

Therefore you will need to reference the value.



now if that does not work, you will have to look through the options and match the value and than select it.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
You were exactly right. I was capturing the option value instead of the item index so on refresh button click there was no index that could be found.

Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Javascript to Select an Item in a Select List
 
Similar Threads
id attribute of FORM doesnt work on Netscape ??
when focus to select drop down focus go to textbox, how do?\
how to disable if one or more check boxes selected
Jsp code in javascript function
Focus issue in IE