I have multiple list items,i just want to do that a user only select upto 5 options. not more than that. if the user select more than 5 option the list item by defualt disabled.
JS
$(function () {
//Checkboxes
$("#chk>li>p").click(function () {
if($(this).hasClass("active")) {
if($("#chkResult").val() != "") {
$("#chkResult").val();
}
} else {
if($("#chkResult").val() == "") {
$("#chkResult").val($(this).html());
} else {
$("#chkResult").val($("#chkResult").val() + "," + $(this).html());
}
}
$(this).toggleClass("active");
});
});
CSS
ul li{
list-style:none;
float:left;
margin-right:20px;
cursor:pointer;
}
ul li.active{
text-decoration:underline;
}
HTML
<form id="test" action="">
<ul id="chk">
<li><p>One</p></li>
<li><p>Two</p></li>
<li><p>Three</p></li>
<li><p>Four</p></li>
<li><p>Five</p></li>
<li><p>Six</p></li>
<li><p>Seven</p></li>
<li><p>Eight</p></li>
<li><p>Nine</p></li>
<li><p>Ten</p></li>
</ul>
<br />
<input id="chkResult" type="text" />
</form>