How to check multi-sweep?

So, the situation is this: I create a drop-down list using the jquery.multiselect plugin in the form, but I need to check if some value is selected if not one or more values ​​are selected. I want to throw a warning or something when someone tries to submit a form.

HTML code

<form id="RNA" name="RNA"> <select size="5" name="sampleMut[]" multiple="multiple" id="sampleMut"> <option value="41" >41</option> <option value="48" >48</option> <option value="65" >65</option> <option value="102" >102</option> </select> </form> 

JavaScript code

 $(function(){ $("#sampleMut").multiselect(); }); 

jQuery version 1.8.3

jquery.multiselect 1.13

+4
source share
2 answers

Try the following:

 $(function(){ $('form').submit(function(){ var options = $('#sampleMut > option:selected'); if(options.length == 0){ alert('no value selected'); return false; } }); }); 

Fiddle: http://jsfiddle.net/aDxu8/1/

+10
source

With this you can get the number of selected parameters.

 $("#sampleMut option:selected").length; 
+3
source