sticky multiple select box

Posted on 2003-02-28
Medium Priority
Last Modified: 2008-02-01
The default properties of a multiple select form box are as follows:

click on an item in the select box and it becomes highlighted. Click on another item in the select box and the first item becomes un-highlighted. If you want to highlight two items at once, you need to hold down the ctrl button when making a second (or nth) selection.

I am trying to find a script that will allow the following:

click on an item in a multiple select box to highlight the item. click on another item in the select box and not only would it be selected, but the previous selection would also stay selected, thereby eliminating the need to hold down the ctrl button for multiple selections. However, if a highlighted item is clicked on again, it should become un-highlighted.

Has anyone seen a script for a multiple select box that can do this?

thanks for all your help.


Question by:wfenton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

spiritwithin earned 152 total points
ID: 8045538
Alright mate, i wrote the thing for you.

Paste it all into a blank html file, load up, and test. Here you go: (btw. i did ONLY test with MS Internet Explorer, you have to translate the code for other browsers yourself - if needed)


<script language="javascript" type="text/javascript">

// I do not know any script like that. However, i think it would be possible to do it. I do not comment here to get points, in this case i only want to help. So all i can do is tell you how it could be done:
// Make an Array:

/* TODO:
   Fill the array with as much zeroes, as your multiple
   select box has items. So if your selectbox contains for
   example 3 names, then add 3 zeroes to the array.
   If you work dynamically, for example with php, then do it
   like that: (note that $elementCount is the number of
               elements in the selectbox. If you do not
               know it at the time of placing the javascript
               into the file, then precalculate the selectbox
               contents, and set $elementCount to it's element
    printf("var arSelect = new Array(");
    for ($iCtr = 0; $iCtr < $elementCount; $iCtr++) {

var arSelect = new Array(0,0,0,0,0,0,0);

// Make a function:

function itemCheck(selectBox) {
 var iCtr = 0;
 for (iCtr = 0; iCtr < selectBox.options.length; iCtr++) {
  if (selectBox.options[iCtr].selected == true) {
   if (arSelect[iCtr] == 0) {
    arSelect[iCtr] = 1;
   } else {
    arSelect[iCtr] = 0;

function arrayToSelectBox(selectBox) {
 var iCtr = 0;
 for (iCtr = 0; iCtr < selectBox.options.length; iCtr++) {
  selectBox.options[iCtr].selected = false;
 for (iCtr = 0; iCtr < arSelect.length; iCtr++) {
  if (arSelect[iCtr] == 1) {
   selectBox.options[iCtr].selected = true;


<form name="x" method="post" action="nothing">
 <select multiple style="width: 200px;" name="testBox" onchange="javascript:itemCheck(this);">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
LVL 28

Assisted Solution

sybe earned 148 total points
ID: 8047204
var arrMyDropDown = new Array();

function DropDownToArray() {
    for(var i=0;i<document.myform.myselect.options.length;i++) {
        arrMyDropDown[i] = false;

function AdvancedSelect(j) {
     var oDropDown = document.myform.myselect;
     arrMyDropDown[j] = !arrMyDropDown[j];
    for(var i=0;i<oDropDown.options.length;i++) {


<body onload="DropDownToArray()">

<form name="myform">
<select name="myselect" onChange="AdvancedSelect(this.options.selectedIndex);" multiple size="10">


LVL 16

Expert Comment

ID: 10096317
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: spiritwithin {http:#8045538} & sybe {http:#8047204}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question