All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

jQuery On Checkbox Checked

Last Updated : Mar 11, 2024

jQuery On Checkbox Checked

In this article we will show you the solution of jQuery on checkbox checked, one of the many sorts of input fields we frequently use is the checkbox, which enables visitors to interact with website pages and generally POST data to the backend by selecting the checkboxes that apply to a certain scenario.

Checkboxes that are a part of a single group are not mutually exclusive, unlike radio buttons (which are a part of radio groups), thus a user can choose as many boxes as apply.

When determining if some options are picked, keep this in mind.

During life there are many ways to accomplish the same thing, and this circumstance is no different.

You can select the method that best suits your use case among the various methods we can determine if such a checkbox is selected or not.

By altering the confirmed property of such input type, there are two ways to dynamically check the checkbox that is now selected.

Step By Step Guide On jQuery On Checkbox Checked :-

<html>
<head>
    <title>
TalkersCode checkbox check
       </title>
    <script src=
"https://code.jquery.com/jquery-2.2.4.min.js">
    </script>
</head>
<body>
    <center>
        <h1 style="color: green">
         TalkersCode
        </h1>
        <b>
          jQuery Check/Uncheck Checkbox
        </b>
        <p>
            <input type="checkbox" name="option" id="front">
            Front-End
            <input type="checkbox" name="option" id="back">
            Back-End
        </p>
        <p>
            <button type="button" class="check-front">
                Subscribe Front-End
            </button>
            <button type="button" class="check-back">
                Subscribe Back-End
            </button>
            <button type="button" class="reset">
                Reset
            </button>
        </p>
        <script type="text/javascript">
            $(document).ready(function1() {
                $(".check-front").click(function2() {
                    $("#front").prop("checked", true);
                });
                $(".check-back").click(function2() {
                    $("#back").prop("checked", true);
                });
                $(".reset").click(function() {
                    $("#front").prop("checked", false);
                    $("#back").prop("checked", false);
                });
            });
        </script>
    </center>
</body>
</html>
  1. The first step is to write <HTML>, which tells the browser what version of HTML we're using. A tag is the first element of an HTML document.
  2. Use the <head> tag to describe the project's heading. In contrast to the final brackets, which are closed, the title and final brackets both are open. External style sheets, also known as step-by-step style sheets, appear on a webpage based on the URL or path.
  3. Next, we create the font size and weight in style.
  4. Then we style by closing our eyes.
  5. The <script> tag was then added. The script tag also includes the javascript google API run or an explanation of the code or file we used.
  6. The script is then closed.
  7. The <body> tag, which describes the webpage's body, is then placed after this. This is where the website's content is written.
  8. A message will appear if the Yes checkbox is selected, and you then click the Submit button.
  9. Clicking the Submit button on a form with unchecked checkboxes will bring up an error message.
  10. Then we close </script> </center> </body>

Conclusion :-

I hope this article on jQuery on checkbox checked helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Ashish

Ashish is a dynamic and motivated individual with a passion of programming and an experienced programmer having 3+ years of experience in various languages like Java, Python, HTML, CSS, JavaScript, jQuery and various frameworks like Bootstrap

Follow Ashish On Linkedin 🡪