Share
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to select limited number of checkboxes with Jquery?
Sponsered Link
#1
See the code below and suggest that how can i select multiple check boxes in this code with a limit of maximum 3.

<div class="from_ajax" id="honda-car" style="display: block;">
<p style="margin-bottom: 5px; font-weight: bold; font-size: 14px;border-bottom: 4px solid #0C3;">Select Models (Upto Five):</p>
<p class="width_33_fl">
<input type="checkbox" value="133" name="selected_make" id="133" onclick="select_models(133);">&nbsp;&nbsp;Accord </p>
<p class="width_33_fl">
<input type="checkbox" value="134" name="selected_make" id="134" onclick="select_models(134);">&nbsp;&nbsp;Accord Tourer </p>
<p class="width_33_fl">
<input type="checkbox" value="135" name="selected_make" id="135" onclick="select_models(135);">&nbsp;&nbsp;Acty </p>
<p class="width_33_fl">
<input type="checkbox" value="136" name="selected_make" id="136" onclick="select_models(136);">&nbsp;&nbsp;Acura </p>
</div>
Reply
#2
Try this one it will work for you.
function select_models(id){
var checkboxes1 = $("#" +id);
var numBoxesChecked = ($('#'+checkboxes1+ ' p.width_33_fl input:checkbox:checked').length);
$(p.width_33_fl input[type="checkbox"]').filter(':not(:checked)').prop('disabled', numBoxesChecked >= 3);
}

It will select not more than 3 checkboxes.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Tell Me What are the Benefits of Using Jquery Reham 1 1,891 03-19-2015, 04:19 PM
Last Post: Reham

Forum Jump:


Users browsing this thread: 1 Guest(s)