Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Check up all Checkbox using Javascript and AJAX
if (this.checked != true) {
  this.checked = true;
}    
else {
  this.checked = false;
}

Above code enables Check up All and Check out All function. However, I found that if any of check box is reversely checked by user, every output reverses.

How should I change in order to acheive followings when button is clicked?

  1. Check Up All box (Acheive)
  2. check Up any box that isn't checked (Problem)
  3. Check Out every box when all boxes are checked (Acheive)

Belows is the full code:

function display() {
  $.ajax({
     url: "test.php",
     type: "get",
     data: {
              a: $('#selectest option:selected').val()
           }
         }).done(function(data) {
                    $('#result').text(data);
                    alert("Checking test");

                    $('input:checkbox[class='+data+']').each(function() {
                      if(this.checked != true){
                      this.checked = true;
                        }

                      else{
                        this.checked = false;
                        }
                    });
                  });
                }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Was the user name Undefined actually available, or did you find a glitch in the matrix?

Your question contradicts your code. This answer is for your question. Your code appears to be setting checkbox states from an ajax call, which is something entirely different.

Since you're using jQuery, you can use the :checked selector. Then you can just check if the number of checked checkboxes is equal to the total number of checkboxes, and toggle .prop('checked') accordingly.

In this snippet, if all checkboxes are checked, all checkboxes will be unchecked (item 3). If not all checkboxes are checked, all checkboxes will be checked (item 1 and 2).

$('button').on('click', function() {
  $('input[type="checkbox"]').prop('checked',
    $('input[type="checkbox"]:checked').length !==
    $('input[type="checkbox"]').length
  );
});
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<button>toggle</button>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!