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.

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-form-tld.html#spring-form.tld.checkboxes

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.

credit: https://stackoverflow.com/a/16161874/5039001


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -