Jelle De Loecker
Jelle De Loecker

Reputation: 21945

Detecting "enter" keyup event on checkbox

I've got a checkbox called 'beveiligdj'. It looks like this:

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

When you select it (by keyboard) and then press enter, it should go to the #beveiligdn input (also a checkbox) But it does not!

   $('#beveiligdj').keyup(function(event) {

    if(event.keyCode == 13) {
        checked = $('#beveiligdj').is(':checked');

        if(checked) {
            $('#beveiligdn').focus();
        }
    }

   });

It just goes to the following field. How can I fix that?

Upvotes: 4

Views: 5758

Answers (1)

Oleg
Oleg

Reputation: 221997

You can try to use the old trick with the setting of the focus inside of setTimeout:

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

You can even try to use 0 instead if 100.

Upvotes: 2

Related Questions