Textbox change event not firing in chrome

google-chrome, jquery, onchange, textbox

Solution

You could always roll your own change function by using blur:

$('.sample.dynamic').data('last','').on('blur', function() {
    var last = $(this).data('last');
    if (this.value!=''&&this.value!=last) myJsFunction();
    $(this).data('last', this.value);
});

Problem

I have a textbox ``` <input name="tx1" size="10" type="text" id="tx1" class="sample dynamic format" maxlength="10" /> ``` Textbox change and keyup events are bind to two different functions. ``` $('.sample.dynamic').change(myJsFunction); $('.format').keyup(function (e) { formatfn(this, e); }); ``` This is my formatfn: ``` function formatfn(sValue, e) { //Do some formatting $(sValue).val(newVal); return newVal; } ``` Both events working fine in IE and firefox but in chrome only keyup function is working and change event is not fired. if i comment the below line in formatfn then change event start firing in chrome as well. ``` //$(sValue).val(newVal); ``` But i can not comment this line as i need to apply the formatting on every keypress. I have looked two similar questions here and here but couldn't find the answer. Update : Formatfn is doing various formatting stuff, but just to give you idea about newval variable i am adding some related code here: ``` var newVal = $(sValue).val(); if (newVal != "") newVal = parseInt(RemoveCommas(newVal), 10).toString(); var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); while (sRegExp.test(newVal)) { newVal = newVal.replace(sRegExp, '$1,$2'); ```

Original source