Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  3] [ 1]  / answers: 1 / hits: 21881  / 12 Years ago, sat, december 15, 2012, 12:00:00

So the situation is this: I'm creating a dropdown box using the jquery.multiselect plugin on a form, but I need to check if there's some value selected, if there isn't one or more values selected I wanna throw a alert or something when some one tries to submit the form.



The 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>


The JavaScript Code



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


jQuery version 1.8.3



jquery.multiselect 1.13


More From » html

 Answers
54

Try this:



$(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/


[#81404] Thursday, December 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleedayanarar

Total Points: 303
Total Questions: 90
Total Answers: 102

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;