472,127 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Multiselection on simple click with HTML/JavaScript

Is there any way to multiselest the options without holding the ctrl or Shift key..
Dec 11 '07 #1
3 1398
428 256MB
Use a group of checkboxes instead of a select for this.
Dec 11 '07 #2
5,390 Expert Mod 4TB
yes ... that would be a better way ... however you could use something like the following example:

<script type="text/javascript">
var selected = {};

function select_option(opt) {
if (typeof selected[opt.value] == 'undefined') {
selected[opt.value] = 1;
} else {
delete selected[opt.value];

var s = opt.parentNode.getElementsByTagName('option');

for (var i = 0; i < s.length; i++) {
if (typeof selected[s[i].value] != 'undefined') {
s[i].selected = true;
} else {
s[i].selected = false;

<select multiple>
<option value="1" onclick="select_option(this);">1</option>
<option value="2" onclick="select_option(this);">2</option>
<option value="3" onclick="select_option(this);">3</option>
kind regards
Dec 11 '07 #3
Use a group of checkboxes instead of a select for this.
Yeah..thats a good idea..
Dec 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Wayne Davis | last post: by
4 posts views Thread by timothy ma and constance lee | last post: by
13 posts views Thread by LRW | last post: by
13 posts views Thread by lost hope | last post: by
9 posts views Thread by Astra | last post: by
1 post views Thread by www.web20developers.com | last post: by
2 posts views Thread by smithtap | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.