godlark
godlark

Reputation: 157

Why browser doesn't fire change event

I have

<input type="text" id="pies" value="" />

and

$( document ).ready(function() {
    $('#pies').on('change', function() { alert('cham'); });
    $('#pies').focus();
    $('#pies').val('kooooo');
    $('#pies').blur();
});

Why browser doesn't fire change event? How can I make that browser will fire change event. I don't want to trigger "change" manually, because if I will trigger change, in some cases trigger change will be triggered twice. This is only example.

Upvotes: 1

Views: 576

Answers (3)

Premshankar Tiwari
Premshankar Tiwari

Reputation: 3106

Better use keypress instead of change

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 121998

You have to do it manually

$('#pies').change();

As docs says

The change event is sent to an element when its value changes. This event is limited to elements, boxes and elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

In auto complete case try to do $("#pies").trigger("autocompleteselect");

Upvotes: 1

flow
flow

Reputation: 5038

Call the change using :

$('#pies').change();

Upvotes: 1

Related Questions