Event onkeyup (Javascript/Jquery) triggered repeatedly makes browser lock

Asked

Viewed 22 times

1

On my page I have a list with some buttons representing data that are presented in another section of the page when the "Submit" button is clicked, triggering the submit function. I added this function that receives a term from the list to submit the data without having to click the button, just by pressing "Enter" on the keyboard. In addition to "Enter", the function had the "Left" and "Right" direction keys to select and display the previous or next item in the list. It turns out that when the event is triggered repeatedly (more or less like the function would be used by the user) the browser starts crashing and does not recover. Just closing and reopening to work again. Follows excerpt from the code:

function cursor(c){
    $(document).on('keyup', function(e){
        e = e.which;
        if (e == 13) {
            num = parseInt(c, 10);
            obj = listaGC[num];
            submeter(obj);
        }
    })
}

If anyone can explain to me why this happens, or rather how to get around it, I’d appreciate it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.