Detect "enter" keyup event on checkbox

I have a beveiligdj flag. It looks like this:

<label><input type="checkbox" id="beveiligdj" name="beveiligdj" value="j">Ja</label> 

When you select it (on the keyboard) and then press Enter, it should go to the #beveiligdn input (also a check box). But this is not so!

  $('#beveiligdj').keyup(function(event) { if(event.keyCode == 13) { checked = $('#beveiligdj').is(':checked'); if(checked) { $('#beveiligdn').focus(); } } }); 

He just moves on to the next field. How can i fix this?

+4
source share
1 answer

You can try using the old focus trick inside setTimeout :

 setTimeout(function(){ $('#beveiligdn').focus(); },100); 

You can even try using 0 instead of 100.

+2
source

Source: https://habr.com/ru/post/1341507/


All Articles