kqlambert
kqlambert

Reputation: 2711

javascript jquery function trigger solution

I have a function that is currently triggered by a focusout of an input element via

$('#wrapper').on('focusout','input[name=state]',function(){ 
    /* execute function */
});

The problem I am having is if someone decides to just skip that element with say a mouse click (as this input element is auto filled using the ziptastic plugin) then the function will not trigger. I tried .on('change') but that did not seem to work.

What would be the best way to trigger this function once input[name=state] has been filled out.

Upvotes: 0

Views: 57

Answers (2)

Ian Routledge
Ian Routledge

Reputation: 4042

Add a change event handler too:

$('#wrapper').on('focusout change','input[name=state]',function(){

And then also trigger the change event ($('#wrapper input[name=state]').change()) after the ziptastic plugin has been run. The change event won't fire if the value is set by .val("something").

Upvotes: 1

Halcyon
Halcyon

Reputation: 57729

You can use onchange, it occurs either before or after the onblur.

Upvotes: 0

Related Questions