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,179 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,179
Overall visits to all the topics: 4,977,410
Daily average (Calculated from the website subscription day): 2,064.46
Optional sorting commands:
Normal order: click here
Order by amount of visits: click here
Order by category: Programming Javascript
Current order: by category: Programming Php
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:
Php Date: Full Disaggregated Date Difference Accounting Timezones And Daylight Identification Number: 453 Visitors: 8,729 PHP Date: Disaggregated Date Difference As Interlapsed Days Hours Minutes Second Identification Number: 452 Visitors: 8,889 PHP Pass To Javascript Php Array Associative Array Or Matrix Identification Number: 419 Visitors: 10,858 PHP: Retrounpad A Matrix Array Table: Remove Shared Empty Columns Identification Number: 412 Visitors: 9,306 PHP: Strip Tags But Register Offsets. Replace Text Without Affecting Html Tags. Identification Number: 407 Visitors: 9,373 Php Check Whether A Web Site Or A Web Resource Exists/Responds Identification Number: 391 Visitors: 12,395 Php: Get Value Of Specific Html Meta Tag Identification Number: 389 Visitors: 17,814 Php Given Url Fetch Youtube Video Codes Embed/Include Video In Other Webpage Identification Number: 388 Visitors: 18,257 Php Find Length Of Texts Or Longest Within Instances Of A Given Html Tag Type Identification Number: 387 Visitors: 14,683 PHP: Match Each Array Item Once With All The Other Array Items Identification Number: 370 Visitors: 14,332
External services
This page of this subscriber uses external services: Hide