Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple select list without a keyboard

Status
Not open for further replies.

Nebooaw

Programmer
Jun 1, 2001
142
0
0
GB
Hi, i have a list/menu where i need to be able to select/deselect and multiple select items only by using a mouse, does anyone know how i can do this without using the "Ctrl" key on the keyboard?

Kindest thanks.
 

For some reason, I thought this would be easier than it was! The following works in FF 1, NN 7, and Opera 7. In fact, it should work in any browser that supports the onclick event for option elements - which does NOT include IE 6.

Code:
<html>
<head>
	<script type="text/javascript">
	<!--
		var selectMode = true;
		var selectedElements = [];

		function chooseOption(whichOption) {
			selectedElements[whichOption] = selectMode;
			var opts = document.forms['myForm'].elements['mySelect'].options;
			for (var loop=0; loop<opts.length; loop++) opts[loop].selected = false;
			for (var loop=0; loop<selectedElements.length; loop++) opts[loop].selected = selectedElements[loop];
		}
	//-->
	</script>
</head>

<body>
	<form name="myForm">
		<select name="mySelect" size="10" multiple="multiple">
			<option onclick="chooseOption(this.index);">Option 1</option>
			<option onclick="chooseOption(this.index);">Option 2</option>
			<option onclick="chooseOption(this.index);">Option 3</option>
			<option onclick="chooseOption(this.index);">Option 4</option>
			<option onclick="chooseOption(this.index);">Option 5</option>
			<option onclick="chooseOption(this.index);">Option 6</option>
			<option onclick="chooseOption(this.index);">Option 7</option>
			<option onclick="chooseOption(this.index);">Option 8</option>
			<option onclick="chooseOption(this.index);">Option 9</option>
			<option onclick="chooseOption(this.index);">Option 10</option>
			<option onclick="chooseOption(this.index);">Option 11</option>
			<option onclick="chooseOption(this.index);">Option 12</option>
			<option onclick="chooseOption(this.index);">Option 13</option>
			<option onclick="chooseOption(this.index);">Option 14</option>
			<option onclick="chooseOption(this.index);">Option 15</option>
		</select>
		<br />
		<input type="radio" name="selectStyle" checked="checked" onclick="selectMode = true;" />Select<br />
		<input type="radio" name="selectStyle" onclick="selectMode = false;" />Unselect<br />
	</form>
</body>
</html>

Hope this helps,
Dan

 

Nebooaw,

I'm just wondering if this worked for you as intended. You never did get back to say...

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top