The Identification Number and Password fields need to be filled in. Moreover, you cannot send messages devoid of contents Adding further data is not allowed because this topic has been closed Print You provided no password: you have to write it in the textfield beside the command delete for the topic you want to delete Are you sure you want to delete this comment? You did not cast a vote. You need to cast a vote by selecting a radio button. Impossible to proceed Provide the project number Insufficient form parameters: you forgot to fill in some field/s
 
member picmember pic
 
Snippets of A
 
info Below you can find the text of the snippet you want to read, and the list of the other snippets by this author if available.
What are snippets?
Share on MySpace

Javascript Select And Unselect Multiple Options Without Using CTRL Or Loops

Snippet: Identification Number »   Snippet: Inclusion syntax »
Visitors: 11,192 Tagged by its author as: Programming Javascript Characters (in origin): 3,787 (pages: ~ 1)
Author: Em@il Permalink Cast your vote for this topic Printable version
OBJECTIVE: given a drop down menu (select tag) that allows multiple selections of options, create a function that permits the multiple selections and deselections without keeping pressed the ctrl key on the keyboard, and also without having to loop all the options in order to achieve the goal (which may cause significant delays in case of menus that include a few hundreds of options, which may happen).
function selections(sel){
if(!sel['storage']){sel['storage']={};};if(sel['size']>sel.options.length){sel['size']=sel.options.length;};if(sel.selectedIndex<0){return;};
var currentIndex=sel.selectedIndex;sel.selectedIndex=-1;
if(!sel['storage'][currentIndex]){sel['storage'][currentIndex]=true;}else{delete sel['storage'][currentIndex];}
for(var i in sel['storage']){sel.options[i].selected=true;}
/*keep this comment to reuse freely
http://www.fullposter.com/?1*/}
Remove colors  
 
INPUTS: only one argument, the select object passed as the keyword this.  
 
RETURNS: nothing.  
 
CAVEATS: works only if implemented via the onclick event on the given menu.  
Works on all major browsers.  
Note that some browsers do not allow reading onclick events (neither onmouseup or onmousedown or any other similar events) set on the options (no matter whether hardcoded or dynamically assigned); therefore the function relies on the selectedIndex property as passed to the select object, and yet on a multiple selection menu such property would always return only the topmost selected option index: therefore the function stores all the given selections (de-selections being, of course, another click onto an already selected option) and resets to -1 the selectedIndex as soon as it has read the latest; this means that, actually, the function reads each time a menu without any previous option selected (sel.selectedIndex=-1) except the current one, and as soon as it has done this, it reassigns all the previous selections. This may lead to ultrafast flashes of the menu.  
 
Only one argument which must be keyword this.  
 
The menu must not carry empty allocations that could be clicked, which happens when the size of the menu is higher than the amount of options it accommodates; to this purpose, at each run the function resizes the menu accordingly to be sure this possibility never occurs.  
 
Assigns to the affected menu a spurious attribute named storage (which must not be overwritten by other subroutines): this is an associative array. A 'regular' numerically indexed array object would have not fit, for upon assigning to a regular array any numerical index it would automatically produce an array whose length is given by the higher index assigned (which may lead to long arrays populated with nonsensical empty entries that nonetheless would demand of being scanned via a throughout loop).  
 
Example of use:
<script>
//include the function!
</script>

<form>
<select multiple="multiple" size="8" onclick="selections(this);">
	<option value="0">zero</option>
	<option value="1">one</option>
	<option value="2">two</option>
	<option value="3">three</option>
	<option value="4">four</option>
	<option value="5">five</option>
	<option value="6">six</option>
</select>
</form>
Remove colors
Printable version To exclude hyperlinks from the print, check the checkbox »
Rss

Cast your vote for this topic

To perform this operation it is not necessary to be Full Poster members.
«Negative Positive»
Click here to save your vote (Current average: 0.00, Voters: 0)
Are you the author of this topic and do you want to append quickly more text? click here
Other topics
This subscriber has a blog too: Read the blog: 57 Shoutbox: 103 reviews: 153
Visitors: 11,192
Overall visits to all the topics: 4,983,806
Daily average (Calculated from the website subscription day): 2,065.40
Optional sorting commands:
Normal order: click here
Order by amount of visits: click here
Order by category: Programming Javascript
Current order: by category: Scientifical Reviews
Other categories available for this author (Limited data report: 100):
Advice: Martial Arts and Self Defense(4), Books(236), Critical Reviews and Essays(4), Dictionaries(1), Emergency Care(4), Epistles Letters and Advice(5), Fantasy Epics and Fables(1), History and Documents(5), Humor and Jokes(2), Methematics(2), Music and Lyrics(6), News Digests and Press Reviews(1), Novels Poetry and Stories(3), Philosophy Reviews(7), Poetry(1), Programming(4), Programming Ajax(2), Programming Javascript(82), Programming Php(52), Psychology(1), Quotes(1), Religion Esoterica and Spirituality(12), Scientifical Reviews(4), Self Improvement(1), Sport Activities and Apparels(2), Tarots(1)
Showing topics: 1, 10
Available total: 448
View only a list of the snippets by this author: click here.
Other topics available for this author: click on any title below to view the complete item:
Henri Poincaré: Mathematical Creation Identification Number: 385 Visitors: 15,244 Entropy Revised - At A Glance Identification Number: 380 Visitors: 14,645 Richard Feynman: Cargo Cult Science Identification Number: 365 Visitors: 14,599 Erwin Schrödinger: The Fundamental Idea Of Wave Mechanics. Nobel Lecture. Identification Number: 286 Visitors: 11,400
External services
This page of this subscriber uses external services: Hide