jquery2

Validate HTML CheckboxList using jQuery

HTML checkbox list is slightly different. The main problem is that it can’t be accessed using ID because every checkbox will have different ID. But they share one common attribute which is “name“. So while accessing checkboxes in jQuery, need to use “name” attribute.

Let’s declare a HTML checkboxlist.

<input type="checkbox" name="technologies" value="jQuery" /> jQuery <br/>
<input type="checkbox" name="technologies" value="JavaScript" />JavaScript <br/>
<input type="checkbox" name="technologies" value="Prototype" /> Prototype<br/>
<input type="checkbox" name="technologies" value="Dojo" /> Dojo<br/>
<input type="checkbox" name="technologies" value="Mootools" /> Mootools <br/>

As you can see there are 5 checkboxes and the validation would be to select at least 3 technologies. And on click of button, validate the checkboxlist. To find out, how many checkboxes are checked, use length property to find out.

$(“input[name=’technologies’]:checked”).length; will give count of checked checkboxes out of the list.

$(document).ready(function() {
    $('#btnSubmit').on('click', function(e) {
        var cnt = $("input[name='technologies']:<wbr>checked").length; if (cnt < 3) { alert('Select at least 3 technologies'); e.preventDefault(); } else alert('Well Done!!!!'); }); });

See result below.

See Complete Code

Feel free to contact me for any help related to jQuery, I will gladly help you.

Related Posts


11 thoughts on “Validate HTML CheckboxList using jQuery

  1. Diego Fogerty

    I just want to tell you that I am just newbie to blogs and really savored you’re web blog. Very likely I’m going to bookmark your blog post . You surely come with very good article content. Thanks for sharing your web-site.

    Reply
  2. Daniela

    Great post admin thank you. I found what i was in search of here. I will review entire of posts in this day time

    Reply
  3. http://www.youtube.com/watch?v=lc3t0udQaDU

    The Zune concentrates on being a Portable Media Player. Not a web browser. Not a game machine. Maybe in the future it’ll do even better in those areas, but for now it’s a fantastic way to organize and listen to your music and videos, and is without peer in that regard. The iPod’s strengths are its web browsing and apps. If those sound more compelling, perhaps it is your best choice.

    Reply
  4. Richie Mccarraher

    Thanks for your your content really interesting. We love our Kindle and the best site for tips and tricks is coolkindles.

    Reply
  5. Get Windows Xp Product Key

    I think this is among the most vital info for me. And i’m glad reading your article. But should remark on some general things, The website style is wonderful, the articles is really nice : D. Good job, cheers

    Reply
  6. Kelvin Pagnozzi

    I know this is actually boring and youre simply skipping to another location comment, but I merely wished to throw you a big thanks! We actually discovered this on yahoo, and im happy I did so. Ill definitely be coming back

    Reply
  7. Melina Rehse

    I simply want to tell you that I’m beginner to blogs and certainly liked you’re web blog. Very likely I’m want to bookmark your website . You absolutely have exceptional article content. Thanks for sharing with us your web-site.

    Reply
  8. Ismael Hongeva

    I simply want to mention I am just new to weblog and actually enjoyed your website. Very likely I’m going to bookmark your blog post . You surely have good well written articles. Thanks a bunch for sharing with us your web site.

    Reply
  9. chrisdurbin@gmail.com

    I’m not positive where you’re getting your info, however good topic. I needs to spend a while learning more or working out more. Thank you for fantastic info I was in search of this info for my mission.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *


*