[thelist] Script to select all options in select dropdown

Joe Crawford joe at artlung.com
Thu, 02 Dec 1999 09:19:32 -0800


"Miller, Bart" wrote:
> 
> I am trying to write a script to select all options in a dropdown menu.
> This would be the equivalent of holding down the control key as you click on
> each item.  But for some reason the code below only selects the last one in
> my loop and not all of them as I would expect. Any ideas?  Here's the code:

Cool idea - never would have thought of this use of a select. Cool.

Here's a version that appears to work.

<SCRIPT TYPE="text/javascript" LANGUAGE=JAVASCRIPT>
<!--
function selectall() {
	for ( i=0;
		  i<document.forms[0].subject.options.length;
		  i++){
		
	document.forms[0].subject.options[i].selected = true;

	}
}
//-->
</SCRIPT>

<FORM>
<SELECT NAME="subject" SIZE=4 MULTIPLE>
	<OPTION>First</OPTION>
	<OPTION>Second</OPTION>
	<OPTION>Third</OPTION>
	<OPTION>Fourth</OPTION>
</SELECT>

<INPUT TYPE="button" ONCLICK="selectall()" VALUE="Select All">

</FORM>


	- Joe
 _________________________________________________________
 Joe Crawford { ArtLung } _________ mailto:joe@artlung.com
 Web Developer + Designer  ________ http://www.artlung.com
 Former Respiratory Therapist _____ San Diego  . CA .  USA
 San Diego Web Developer? Go to http://www.websandiego.org