internet explorer - Javascript Error in FireFox Not in IE and Chrome -
i use following function decimal validation.the textbox allow enter numbers , .(dot) symbol only.it working fine in ie , chrome.my problem event not defined error.how solve this?i have lot of textbox validation.so create decimal validation common like,
//call function $('.decimalvalidate').live('keypress',function(){ var decimalid=$(this).attr("id"); var decimalval=$('#'+decimalid).val(); var decimalvalidate=applydecimalfilter(decimalval); if(decimalvalidate == false) return false; });
//function decimal validation.it allows 1 . symbol.everything works fine on ie , chrome
function applydecimalfilter(id) { try { return newdecimalfilter(id, event); } catch (e) { alert(e.message); } } function newdecimalfilter(o, event) { if (event.keycode > 47 && event.keycode < 58) { return true; } if ((event.keycode == 8 || event.keycode == 46) && o.indexof('.') == -1) { return true; } return false; }
and use decimalvalidate class in text box as,
input type="text" id="inputloanamount" class="decimalvalidate" style="width:100px"
in firefox, event
isn't global. window.event
undefined
. need pass event parameter. , way, should use .on
instead of .live
if use jquery >= 1.7.
$('.decimalvalidate').live('keypress', function (e) { var decimalid = $(this).attr("id"); var decimalval = $('#' + decimalid).val(); var decimalvalidate = applydecimalfilter(decimalval, e); if (decimalvalidate == false) return false; }); function applydecimalfilter(id, event) { try { return newdecimalfilter(id, event); } catch (e) { alert(e.message); } }
Comments
Post a Comment