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?

MarceloMadnezz
  • 297
  • 6
  • 16

1 Answers1

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.

David
  • 208,112
  • 36
  • 198
  • 279
  • 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 Sep 25 '13 at 18:02
  • 1
    @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 Sep 25 '13 at 18:04
  • @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`. – jcairney Feb 08 '18 at 00:25