Skip to content

Instantly share code, notes, and snippets.

@lyonsun
Last active August 29, 2015 14:02
Show Gist options
  • Save lyonsun/2429d05bc91265531fc7 to your computer and use it in GitHub Desktop.
Save lyonsun/2429d05bc91265531fc7 to your computer and use it in GitHub Desktop.
check if at least one option is selected in a multiple select element
<select id="mySelect" multiple="multiple">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
</select>
<script type="text/javascript">
$(document).ready(function() {
if (!$("#mySelect option:selected").length)
// none is selected
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment