javascript - form validation for at least on select-option is selected -
my form layout similar below:
<form action='' method="post" id='myform'> <select name='select1'> <option value=''>select option</select> <option value='a'> </option> <option value='b'> b </option> <option value='c'> c </option> </select> <select name='select2'> <option value=''>select option</select> <option value='e'> e </option> <option value='f'> f </option> <option value='g'> g </option> </select> <select name='select3'> <option value=''>select option</select> <option value='h'> h </option> <option value='i'> </option> <option value='j'> j </option> </select> </form> <script> $('#myform').validate(); </script>
note: have included jquery.js
, jquery.validate.js
files.
here, 3 select-option in form. need validate @ least 1 select-option only.
function selectvalidate() { var check = false; $.each($('select'), function(index, data) { if (data.val() !== ''){ check = true; } }); return check; }
Comments
Post a Comment