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

Multiselect Select Boxes without CTRL or Shift

Looking for a way to allow Multiselect
on a Select Box only using Mouse Clicks
on Items without having to Hold Down the
Shift or CTRL Keys.  Clicking on an item
would select it, clicking on an already
selected item would unselect it.  Was
wondering if any knows how this can be
done using Javascript?

0
iDude
Asked:
iDude
1 Solution
 
ZvonkoSystems architectCommented:
Try this:

<html>
<head>
<script>
var selCtrl=new Array();
function reSelect(theSel){
 theIndex=theSel.selectedIndex;
 if(selCtrl[theIndex])
   selCtrl[theIndex]=false;
 else
   selCtrl[theIndex]=true;
 for(i=0;i<theSel.options.length;i++)
   if(selCtrl[i])
     theSel.options[i].selected=true;
   else
     theSel.options[i].selected=false;
}
</script>
</head>
<body>
<form>
<select name=mySel multiple
onClick="reSelect(this)">
<option>one
<option>two
<option>three
<option>four
<option>five
<option>six
</select>
</form>
</body>
</html>

Good luck,
Zvonko

0
 
jaysolomonCommented:
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:

Accept: Zvonko {http:#8087326}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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