• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

sticky multiple select box

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.


2 Solutions
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>
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">


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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now