Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:49+00:00 2026-05-27T09:04:49+00:00

I need to check if a checkbox is checked or not in order to

  • 0

I need to check if a checkbox is checked or not in order to display an error message. So far I thought that this should work (if not checked than it should be empty I thought).

CODE

<span id="sc_info" style="float: right; padding-right: 5px;">

<input type="checkbox" name="terms" id="sc_terms" value="" checked="checked" />

<br /><label class="error" for="body" id="terms_error">This field is required.</label>
</form>

<script>
$(document).ready(function() {
    //Story Form
    $('.error').hide();  
    $(".button").click(function() {

    $('.error').hide();  
    var terms = $("input#sc_terms").val();  
    if (terms == "") {  //if is not checked
    $("label#terms_error").show();  //show error message
    $("input#sc_terms").focus(); //focus on an empty element
    return false;  
}  
});  
});
</script>

But this code doesn’t work. can anyone suggest how to check if checkbox is checked?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:04:50+00:00Added an answer on May 27, 2026 at 9:04 am

    Use jQuery’s :checked selector:

    if ($('#sc_terms').is(':checked')) {
        // Checkbox is checked, do stuff
    }
    else {
        // Checkbox is not checked, do stuff
        $("label#terms_error").show();  //show error message
        $("input#sc_terms").focus();
    }
    

    If you simply want to see if it’s not checked:

    if ($('#sc_terms:not(:checked)')) {
            // Checkbox is checked, do stuff
            $("label#terms_error").show();  //show error message
            $("input#sc_terms").focus();
     }
    

    Note: Since you’re using the ID selector, prefacing your selector with input or label is not necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to check if the checkbox is checked or not..
I have this code I am checking wheather checkbox i checked or not.. $('#btnsubmit').click(function()
This is not working $(.gradeA, .gradeU).find(:checkbox).click(function() { if (this.checked === false) { return; }
On a webshop, I need to check if the user has checked this payment
i have requirement where i need to check if apex:inputCheckbox is checked, and if
I am writing a Autohotkey script that need to 'check' and 'uncheck' checkboxes defined
I'm coding this plugin that validates if a series of checkbox groups have at
JSFIDDLE $(document).ready(function() { $(.chk).click(function() { $(.chk:checked).each(function() { $(.+this.id).show(); }); $(.chk:not(:checked)).each(function() { $(.+this.id).hide(); }); //
I need to seperate the checked and unchecked check box from set of check
Consider the following code ( http://jsfiddle.net/FW36F/1/ ): <input type=checkbox onchange=alert(this.checked)> <button onclick=document.getElementsByTagName('input')[0].checked=!document.getElementsByTagName('input')[0].checked;>toggle</button> If you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.