Set input value in keyup, stops change event from firing
<p><em><strong></em> NEW Fiddle: <a href="http://jsfiddle.net/martinnormark/jBZfs/14/" rel="nofollow">http://jsfiddle.net/martinnormark/jBZfs/14/</a> - new isolated example. See how the change event is not fired for Amount 2! **</strong></p>

<p>I have a jQuery plugin for formatting a number in a currency format, as you type.</p>

<p>You can see it in action in this fiddle: <a href="http://jsfiddle.net/martinnormark/Rv4Ug/1/" rel="nofollow">http://jsfiddle.net/martinnormark/Rv4Ug/1/</a></p>

<p>The problem is, if you enter a value of at least 4 digits (causing the need to thousand separator: 1178 becomes 1,178), the change event dies. As long as you stay below 4 digits, not causing a new format, the change event is fired.</p>

<p>In the fiddle, try to enter 12, then 123. You should see a text reading 'change event raised'. And then enter 1234 - and the change event is not fired.</p>

<p>This will have something to do with the manipulation of the input element's value in a keyup event handler:</p>

<pre><code>$this.on("keyup.autoformatcurrency", function(event) {
    if ($.inArray(event.keyCode, keyCodes) &gt; -1) {
        formatCurrency($(this), true);
    }
});
</code></pre>

<p>And the <code>formatCurrency</code> function:</p>

<pre><code>function formatCurrency($this, setCaretPosition) {

    var rawValue = $this.val(),
        floatValue = Globalize.parseFloat(rawValue);

    if ($.isNumeric(floatValue)) {
        var formattedValue = Globalize.format(floatValue, settings.formatString),
            caretPosition = 0;

        if (setCaretPosition) {
            caretPosition = $this.caret().end + (formattedValue.length - rawValue.length);
        }

        $this.val(formattedValue);

        if (setCaretPosition) {
            $this.caret(caretPosition, caretPosition);
        }
    }

}
</code></pre>

<p>(for full source, see the file on Github: <a href="https://github.com/martinnormark/jquery-format-currency/blob/master/src/jquery.formatcurrency.js" rel="nofollow">https://github.com/martinnormark/jquery-format-currency/blob/master/src/jquery.formatcurrency.js</a> )</p>

<p><strong>The question is</strong>, if there's a way to make sure the change event will be fired?</p>

<p><strong>UPDATE - Current state in browsers</strong><br>
<strong>Chrome</strong>: Change event fired, if number is below 4 digits.<br>
<strong>Safari, IE</strong>: Change event is never fired, as long the value is set programmatically. Enter letters instead of numbers will trigger the change event.<br>
<strong>Firefox</strong>: Works!<br>
<strong>Opera</strong>: Works!</p>
