Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unselect an item in a select box?

Tags:

I have an easy question for you today. I have a select box that enables the user to select multiple items. Also, when the user returns to the page, he can see which items he selected and unselect them if necessary. The trouble is that when I try to unselect, the selection just turns gray; it does NOT unselect.

<select name="MySelect" multiple> <option value="1">1</option> <option value="2">2</option> <option value="3" selected="selected">3</option> <option value="4">4</option> <option value="5">5</option> </select> 

So, when the element above renders to the page, I have no way to unselecting the option. The value is STILL getting passed to the form.

Any help?

like image 583
Evik James Avatar asked Jul 29 '11 16:07

Evik James


People also ask

How do I unselect a selected option?

You can deselect any cells within the selected range with the Deselect Tool. Pressing the Ctrl key, you can click, or click-and-drag to deselect any cells or ranges within a selection. If you need to reselect any of those cells, continue holding the Ctrl key and reselect those cells (for Mac, use the Cmd key).

How do I remove a selected value from a Dropdownlist?

The option to be removed is selected by getting the select box. The value to be removed is specified on the value selector (value='optionValue') on the select box. The remove() method is then used to remove this selected option. The find() method can be used to find the option in the value with the value selector.

How do you unselect an online option?

You can deselect options in a multi-value select list by ctrl-clicking it.


2 Answers

You can deselect options in a multi-value select list by ctrl-clicking it.

like image 181
Joseph Marikle Avatar answered Nov 12 '22 17:11

Joseph Marikle


You can use JS object to memorize the status of a row and click action on select (JQuery).

$('#yourselect').click( function(e){                 var i = this.selectedIndex;         if(this.options[i].selectedOld==true){             this.options[i].selected = false;             this.options[i].selectedOld = false;         }         else{             this.options[i].selectedOld = true;         }     }); 
like image 35
Alessandro Battistini Avatar answered Nov 12 '22 17:11

Alessandro Battistini