简体   繁体   中英

How we can choose only 4 from a group of checkbox when the data is coming from the database

I want to show JavaScript alert when user trying to choose more than four values from the group of checkbox the checkbox names are in array

<div class="checkbox alert alert-primary">

    <p><input type="checkbox" id="calorieCheckbox" name="txt_tradesman[]" value="<?php echo $restrad['tradesman_id'] ?>" onClick="return KeepCount()"><?php echo $restrad['fullname'] ?> <p>    

</div>

Here's jQuery version:

$('[name="txt_tradesman[]"]:checked').length

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM