You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anja Friedrichsen <af...@ebi.ac.uk> on 2005/04/06 12:19:40 UTC

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: change selected item in drop down list

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
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:afrie@ebi.ac.uk]
>>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: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: change selected item in drop down list

Posted by Mark Benussi <ma...@hotmail.com>.
I am guessing in this instance you have not changed the variables I supplied
with the script with your actual form and select names.

var options = document.forms['formName'].elements['selectName'].options;

-----Original Message-----
From: Anja Friedrichsen [mailto:afrie@ebi.ac.uk] 
Sent: 06 April 2005 16:24
To: Struts Users Mailing List; mark_benussi@hotmail.com
Subject: Re: change selected item in drop down list

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:afrie@ebi.ac.uk] 
>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: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: change selected item in drop down list

Posted by Anja Friedrichsen <af...@ebi.ac.uk>.
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:afrie@ebi.ac.uk] 
>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: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: change selected item in drop down list

Posted by Mark Benussi <ma...@hotmail.com>.
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:afrie@ebi.ac.uk] 
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org