How to deselect an item in a selection window?

I have a simple question for you today. I have a select box that allows the user to select multiple items. In addition, when the user returns to the page, he can see which elements he has selected and deselect if necessary. The problem is that when I try to deselect, the selection just turns gray; he does not cancel the choice.

<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 item above is displayed on the page, I cannot deselect. The STILL value is passed to the form.

Any help?

+6
source share
2 answers

You can deselect several values ​​in the selection list by pressing Ctrl.

+25
source

You can use the JS object to remember the state of the string and click on the select (jQuery) action.

 $('#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; } }); 
0
source

Source: https://habr.com/ru/post/893882/


All Articles