There is an input in which you can enter a number. Make it so that when you enter a number into this input and focus loss on the page, the checkbox with that number is searched and becomes checked, and the rest of checkboxes become unchecked.

Closed due to the fact that off-topic by user207618, Anton Shchyrov , Igor , αλεχολυτ , Regent 26 Jun '18 at 19:13 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Community Spirit, Anton Shchyrov, Igor, αλεχολυτ, Regent
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    You still continue to write assignments without a hint of trying to solve it yourself - Regent
  • one
    Uiii, in our time, "help" === "do it for me." - user207618
  • What are the difficulties with the task? - Grundy

2 answers 2

$("input[type='number']").blur(function () { $("input[type='checkbox']").prop('checked', false).eq($(this).val()-1).prop('checked', true) }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type=number min=1><br> <input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox><input type=checkbox> 

  • @Other, in general, the question could be turned into a good one by changing to "how to remove all the checkboxes in the group and mark only one of them";) - Qwertiy
  • one
    Let's continue the discussion in the chat . - Qwertiy 7:09 pm

If the checkbox number is in its id (for example, id = "check_1") and the class of all checkboxes is class = "check", then:

 $('input').on('blur',function(event){ var num=$(this).val(); var id='check_'+num; $('.check').each(function(){ (this).checked(false); }); $(id).checked(true); }); 
  • 2
    Have you tested the code you wrote? Instead of (this) , I suspect it should be $(this) , instead of checked(false) - prop("checked", false) . - Regent
  • one
    The prop method, by the way, is able to work with the collection, so .each here. - Regent