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 re:selecting an option from a select box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "re:selecting an option from a select box" Watch "re:selecting an option from a select box" New topic
Author

re:selecting an option from a select box

Tom Hopkins
Greenhorn

Joined: Aug 10, 2001
Posts: 14
I was glad to see this question posted as I previously thought it wasn't possible. This brings me to my next question, can you select multiple options from a select box upon loading a page?
Thanks
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, if "MULTIPLE" is specified in the SELECT clause, it will apear as a list box, and you should be able to have more than one selected items.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Tom Hopkins
Greenhorn

Joined: Aug 10, 2001
Posts: 14
Bosun,
Thanks for your reply, but I don't think I worded my question properly.
I do indeed have MULTIPLE as an attribute to the SELECT tag and as such a user can of course select multiple options from the list box.
My question was related to a post from yesterday wherein someone asked how to select options in a list box from javascript (ie. so that when the page loads certain options are already selected).
Further posts indicated using something similar to
document.formName.selectBoxName.selectedIndex = n;
which works for selecting ONE item from a list box. I wanted to know if anyone knows of a way to select multiple options from javascript.
I hope this makes sense.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Did you try something like this?
var select = document.formName.selectName;
select.options[i].selected = true;
select.options[j].selected = true;
Bosun

Tom Hopkins
Greenhorn

Joined: Aug 10, 2001
Posts: 14
Son of a Gun - it worked. Very cool.
I hate to be a bother, but how would I select a radio button. I know only one can be selected at a time, I'm just wondering how to select from javascript.
Thanks
Tom Hopkins
Greenhorn

Joined: Aug 10, 2001
Posts: 14
Found my own answer to this one.
document.formName.selectName[i].checked = true;
 
Don't get me started about those stupid light bulbs.
 
subject: re:selecting an option from a select box
 
Similar Threads
javascript for select box
How to prepopulate combo boxes on page startup
strugling new bee
Javascript Select Drop-Down Box Question.
JSP and Radio Buttons