Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

re:selecting an option from a select box

 
Tom Hopkins
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tom Hopkins
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found my own answer to this one.
document.formName.selectName[i].checked = true;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic