0

I have lots of input fields using the Jquery Masked Input but I can't figure out how to capture the change of the value on the input.

I have tried:

JQuery.Change()

$('#Selector').bind('input', function () {})

But, no success.

Anyone could help me?

3
  • oninput event should work but IDs must be unique on context page. Hard to help more without seeing any piece of useful code... You could wish to use onblur event instead. Commented Sep 25, 2013 at 17:44
  • You can also use the keyup event which fires when user presses a key . Commented Sep 25, 2013 at 17:47
  • Keyup worked great. Thanks! Commented Sep 25, 2013 at 18:15

1 Answer 1

1

Do you just mean this?:

$('#Selector').change(function () {
    // respond to the change
})

Or, if your elements are dynamically being added to the DOM, you might use:

$(document).on('change', '#Selector', function () {
    // respond to the change
});

(You don't have to use document as the common parent element, any common parent element will work.)

Depending on the type of the input (and sometimes on the browser, unfortunately), you might try other events as well, such as keypress, keyup, even blur in some cases.

Sign up to request clarification or add additional context in comments.

3 Comments

HI David, thank you for your answer. I need to fire a function when the input was changed, in real time, not only when the focus come out of the input. My problem is: I can do that on a normal input field, but in those ho has the MaskedInput, i can't capture the change.
@MarceloMadnezz: Did you try keyup instead of change? I don't think the value of a text input actually changes during typing, it's committed to the DOM after focus leaves the input.
@David While you're right that the change event does not fire until field blur, the current/changing/changed contents of the field are always readable via .value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.