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

89
Views
I have to Iterate thorough check boxes if the value of checkbox is in my array I want the check box to be checked

This is my function and it is not working, My check boxes remain unchecked

$(document).ready(function() {
        var sales_agent_prev_arr = ['21-1', '21-2', '21-3', '21-5', '21-6', '26-1', '26-2', '26-3', '8-1', '8-9', '8-2', '8-3', '8-4', '8-5', '13']
        $('#user_type').on('change', function() {
          if ($(this).val() == 6) {
            $('input[type="checkbox"]').each(function() {
              if ($.inArray(this.value, sales_agent_prev_arr) !== -1) {
                $(this).prop('checked',true);
              }
            });
          }
        })
      });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li><input type="checkbox" value="21-1">View All</li>
  <li><input type="checkbox" value="21-2">check</li>
</ul>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please check the two lines of your code , without them it works fine :

$('#user_type').on('change', function() {
      if ($(this).val() == 6) {
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!