DEMO : Limiting number of user selections of a dropdown listbox with multi option

Try to select more than 3 options. Hold the Ctrl key to select multiple options from the list box.

Restricting number of user selections from Dropdown listbox multi option in JavaScript

JavaScript part
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++)
		total =total +1;
if(total > 3){
alert("Please Select only three") 
document.form1.ckb[j].selected= false ;
return false;

 <form method=post action='' name=form1>
<select name='ckb[]' size=6 multiple id=ckb>
<option value='blue'onclick='chkcontrol(0)'>Blue</option>
<option value='green' onclick='chkcontrol(1)'>Green</option>
<option value='red' onclick='chkcontrol(2)'>Red</option>
<option value='yellow' onclick='chkcontrol(3)'>Yelllow</option>
<option value='white' onclick='chkcontrol(4)'>White</option>
<option value='white' onclick='chkcontrol(5)'>Black</option>
<option value='white' onclick='chkcontrol(6)'>Orange</option>
<option value='white' onclick='chkcontrol(7)'>Pink</option>
<input type=submit></form>

Checkbox Limit Tutorial Checkbox limiting selection Checkbox limiting demo by getElementByName
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


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

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