Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Multi Select Combo Box

Status
Not open for further replies.

rhull

Programmer
May 23, 2001
46
0
0
US
I am tryimg to do a dynamic combo box so I am using JSP to switch the 'selected' in and out. Problem is it breaks the HTML. So I need to assign the 'selected' value somehow.

Something Like
<option value=&quot;Fecci&quot; selected=&quot;false&quot;>Fecci </option>
OR
<option value=&quot;Fecci&quot; ????=&quot;selected&quot;>Fecci </option>

Then I can just switch the assigned value!

Basically is there any other way to select a value without just the word 'selected'?

Thanks!

-R

 
In JavaScript
Code:
document.formname.selectlistname.options[n].selected = true
Where n is the index number of the option you want selected. It's zero based so options[0] is option #1, etc..

If you don't know the index number and want to select based on an option value, you would loop through the options like this.
Code:
function selectOption(value_ref) {
  for(var i = 0; i < document.formname.selectlistname.length; i++) {
    if(document.formname.selectlistname.options[i].value == value_ref) {
      document.formname.selectlistname.options[i].selected = true
    }
  }
}

Then in your HTML, maybe in the onLoad event handler, you can call that function like this.
Code:
selectOption('somevalue')

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top