DEMO : Limiting number of check boxes selected by user by getElementsByName


SelectChoice
PHP
Perl
MySQL
ASP
JavaScript
CSS
HTML
Photo Shop
Try to select more than 3 checkboxes.

In place of limiting the number of selections, we can restrict based on the sum of values of the checkboxes.
We used getElementsByName here
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
var elem = document.getElementsByName('ckb');
for(var i=0; i < elem.length; i++){
if(elem[i].checked==true){
total =total +1;}
if(total > 3){
alert("Please Select only three") 
elem[j].checked = false ;
return false;
}
}
} </script>
Checkbox Limit Tutorial Checkbox limiting by document.form.checkbox Checkbox limiting by value demo
JavaScript Checkbox Reference

Limiting number of selection user can check from a group of checkboxes by using JavaScript


Subscribe to our YouTube Channel here



plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer