My code for this (written probably five years ago) looks very similar, but
maybe two versions would help...

function locateDDValue(drop_down, find_me) {
 found_it = false;
 for (i = 0; (i < drop_down.length) && !found_it; i++) {
  if (drop_down.options[i].value == find_me) {
   found_it = true;
   drop_down.options[i].selected = true;
  }
 }
 return found;
}

Has the minor benefit of telling the caller whether the value was found or
not.  Also, not that this is case-sensitive, so you may want to do some
toLowerCase() calls on find_me and each value checked against from the
dropdown.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Wed, April 6, 2005 11:23 am, Anja Friedrichsen said:
> Thanks for your answer Mark,
>
> I am new with JavaScripts and I tried your example, but it does not
> really work...
>
> I tried to do
>
>     alert(options);
>
> after
>     var options = form.elements['select'].options[i];
>
>
> but nothing happend. What exactly is that line doing?
>
> Thanks, Anja
>
>
>
> Mark Benussi wrote:
>
>
>>Yes you can select an option in a selection, but you would need to know
>> the
>>index of the option.
>>
>>form.elements['select'].options[i].selected = true;
>>
>>When generating the select using the html:options argument your
>> presentation
>>layer wont have much knowledge of the data passed so you will have to
>>recurse the options until you find one that matches your selection on the
>>map.
>>
>>function somethingHappened(mapSelection) {
>>      var options = form.elements['select'].options[i];
>>      for(var i = 0; i < options.length; i++) {
>>              var option = options[i];
>>              if(option.value == mapSelection) {
>>                      option.selected = true;
>>                      break;
>>              }
>>      }
>>}
>>-----Original Message-----
>>From: Anja Friedrichsen [mailto:[EMAIL PROTECTED]
>>Sent: 06 April 2005 11:20
>>To: Struts Users Mailing List
>>Subject: change selected item in drop down list
>>
>>Hi!
>>
>>My application is based on stuts and contains among other thing a
>>dropdown list and a graph. What I want to do, is to change the selected
>>item in the drop down list, when clicking on the corresponding node in
>>the graph.
>>Is it possible to change the selected item in a dropdown list?
>>
>>My drop down list looks like that:
>>
>>                      <html:select property="cvIdentification">
>>                          <html:options collection="cvIdentifications"
>>property="shortlabel" labelProperty="shortlabel" />
>>                      </html:select>
>>
>>Thanks in advanced!
>>
>>Anja
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to