jquery - Java Spring MVC form:checkboxes - how to know if any were checked -
say have following line in jsp:
<form:checkboxes path="appliedplayers" items="${suitableplayers}" itemvalue="id" itemlabel="displayname" />
i disable form-submit button when none of checkboxes checked. like:
$('#checkboxes').change(function() { if (none_are_checked) disablebtn(); });
spring form tags not support this. can check following link supported attributes.
what can done is, can handle scenario @ client side using jquery(like mentioned).
<script> $(document).ready(function(){ $('input[name=players]').change(function() { //alert('hello'); var checkednum = $('input[name="players[]"]:checked').length; if (!checkednum) { // user didn't check checkboxes disablebtn(); } }); }); </script>
explanation: in above code snippet, when checkbox element changes registered function gets called counts number of selected checkbox elements. if 0 enters if condition requirement.
note: above example assumes html attribute name value checkboxes players
. can change jquery selectors appropriately if needed.
Comments
Post a Comment