enter image description here There are several checkbox-ов , you need to select 1 or 2 checkbox , and the rest are chosen independently of them. id , name do not change as used in the program.

 $('#count').keyup(calculate); function calculate() { if ($("#Bort").is(':checked')) sum += 1400; if ($("#Borta").is(':checked')) sum += 2800; } $('input.kartinki').on("click", function() { if ($('#Bort').prop('checked')) { $('#image').attr('src', 'img/kartinki_chekbox/belava/bl_l_310.jpg'); } else if ($('#Borta').prop('checked')) { $('#image').attr('src', 'img/kartinki_chekbox/belava/bl_p_310.jpg'); } }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label for="Bort">1</label> <input class="kartinki" name="Борт" type="checkbox" id="Bort" /> <label for="Borta">2</label> <input class="kartinki" name="Борта" type="checkbox" id="Borta" /> <label for="morilka">3</label> <input name="Морилка" type="checkbox" id="morilka" /> 

  • I think the question is to describe in more detail ... - Air
  • @Air and what exactly to add? - Liana
  • Why not use radio for 1 and 2? And the user is clearer. - Artem Gorlachev
  • Liana, нужно чтобы выбирался 1 или 2 checkbox, а остальные выбирались независимо от них. id нужно чтобы выбирался 1 или 2 checkbox, а остальные выбирались независимо от них. id is a piece from a question that I didn’t quite understand - Air
  • And I agree with @ArtemGorlachev, why then the first two are not type="radio" ? - Air

1 answer 1

Uncheck the second checkbox when clicking on the first one and vice versa.

 $('input.kartinki').on("click", function() { var id = $(this).attr('id'); if(id == 'Bort' || id == 'Borta'){ var img = {'Bort' : "bl_l_310.jpg'", 'Borta': "bl_p_310.jpg"}; if($(this).prop('checked')){ var uncheck = id == 'Bort' ? '#Borta' : '#Bort'; $(uncheck).prop('checked', false); } $("#image").attr('src', "img/kartinki_chekbox/belava" + img[id]); } }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label for="Bort">1</label> <input class="kartinki" name="Борт" type="checkbox" id="Bort" /> <label for="Borta">2</label> <input class="kartinki" name="Борта" type="checkbox" id="Borta" /> <label for="morilka">3</label> <input name="Морилка" type="checkbox" id="morilka" /> 

  • I tried without links to the pictures just to choose checkboxes — it doesn't work in the main code - Liana
  • @ Liana without seeing the code, you will not tell much. - teran
  • the code is very large. In the same way using id: id = "Bort", id = "Borta" that would put a tick on 1 or 2 - Liana