FairyQueen
FairyQueen

Reputation: 2373

Why is page refresh triggering .keyup()?

I have this function:

$('.PhoneNumbers').on('keyup focusout', $('input:text[name^="Customers[0].PhoneNumbers"]'), function (e) {
    phoneRadioBtns(e);
});

The problem is that when I refresh the page it triggers the keyup event and it executes the function, which is not the desired result. Does anyone know how to correct this?

Upvotes: 3

Views: 1390

Answers (1)

Eran Medan
Eran Medan

Reputation: 45775

Does it happen only when you press F5 while inside the input?

(This was the only way I managed to reproduce: try here http://jsfiddle.net/ybuTv/)

One way of solving it is to exclude the F5 button from the event: http://jsfiddle.net/ybuTv/1/

$(function() {
    $('.PhoneNumbers').on('keyup focusout', $('input:text[name^="Customers[0].PhoneNumbers"]'), function(e) {
        if(e.which!=116){
            phoneRadioBtns(e);
        }
    });

});

Upvotes: 1

Related Questions