aspose 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
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply 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: 1261
Thsi causes an error. Please help with correct syntax.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    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: 1261
When I run this code the alert will produce -1 eventhough projindex = 201

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    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: 1261
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Using Javascript to Select an Item in a Select List
 
Similar Threads
id attribute of FORM doesnt work on Netscape ??
Focus issue in IE
how to disable if one or more check boxes selected
Jsp code in javascript function
when focus to select drop down focus go to textbox, how do?\