Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check wether the checkbox is selected or not using jquery

    • 2
    • 2
    • 0
    • 1
    • 0
    • 0
    • 0
    • 407
    Answer it

    "How to check wether the checkbox is selected or not using jquery"

    While working in a project, I got stuck in the following issue.

    This is the code I am using:

    <input type="radio" name="optionsRadiosbillingmethod" id="optionsRadios1-billing-method" value="option1-billing-method" class="required">
    

    This is my Checkbox, I wan't to check wether this checkbox is selected or not using jquery and if it is selected then I wan't its value in my .js file using jquery.

    Anybody have some idea, how to acheive this.... Thanks in Advance..!

 1 Answer(s)

  • With an ID

    $('#' + id).is(":checked")
    

    If you want to check by name

    var $boxes = $('input[name=thename]:checked');
    

    where "thename" is the name of the checkbox. Checking by name come in handy if you have multiple checkboxes to check
    For Example:- If you have an array of checkboxes with same name(creating a checkbox list),you can loop like following.

    $boxes.each(function(){
        //do stuff here with this
    });
    

    And for checking that how many of them are checked in the list:-

    $boxes.length;
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: