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

94
Views
Select only one checkbox HTML

I have a problem with checking only one checkbox... I tried two types of JS code.. But it doesn't work... To check by class, when u click on one element with class 'product-list' to deselect another... Have someone idea how to solve this?

HTML:

<div class="mg-toolbar">
  <div class="mg-option checkbox-custom checkbox-inline">
    <input class="product-list" type="checkbox" name="PDF" value="<?php echo $file_name; ?>">
    <label for="file_1">SELECT</label>
  </div>
</div>

JS Try 1:

<script type="text/javascript">
   $('.product-list').click(function() {
     $(this).siblings('input:checkbox').prop('checked', false);
   );
</script>

JS Try 2:

<script type="text/javascript">
   $('.product-list').on('change', function() {
     $('.product-list').not(this).prop('checked', false);  
   });
</script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If you want to ensure that only one item to be selected at once, then actually that's what radio buttons were invented for (rather than checkboxes). And you don't need any JS code to make that work.

Demo:

<div class="mg-toolbar">
  <div class="mg-option checkbox-custom checkbox-inline">
    <input class="product-list" id="file_1" type="radio" name="PDF" value="File1">
    <label for="file_1">SELECT 1</label>
  </div>
  <div class="mg-option checkbox-custom checkbox-inline">
    <input class="product-list" id="file_2" type="radio" name="PDF" value="File2">
    <label for="file_2">SELECT 2</label>
  </div>
  <div class="mg-option checkbox-custom checkbox-inline">
    <input class="product-list" id="file_3" type="radio" name="PDF" value="File3">
    <label for="file_3">SELECT 3</label>
  </div>
  <div class="mg-option checkbox-custom checkbox-inline">
    <input class="product-list" id="file_4" type="radio" name="PDF" value="File4">
    <label for="file_4">SELECT 4</label>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

change the #c01 and #c02 to the two check box ID's your doing this with. I think this may do what you need it to do. If c01 checked, c02 is unchecked, and vice-versa

 $("#c01").click(function(){
        if($("#c01").is(':checked'))
        $("#c02").prop("checked", false);
    });
    
    $("#c02").click(function(){
        if($("#c02").is(':checked'))
        $("#c01").prop("checked", false);
    });
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!