File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 1490
    
    1
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: 1490
    
    1
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: 1490
    
    1
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