$(function () { $(".curr-cnv .tbl input[type=text]").focus(function () { $(this).select(); }); $('.curr-cnv .tbl input[type=text]').keyup(function () { $(this).val($(this).val().replace('.', ',')); var tl = $(this).val().replace(',', '.') * $(this).closest('.tbl-row').attr('data-value'); $('.curr-cnv .tbl input[type=text]').not(this).each(function () { $(this).val(addCommas((tl / ($(this).closest('.tbl-row').attr('data-value'))).toFixed(4)).replace(',', '#').replace('.', ',').replace('#', '.')); }); }); }); function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); } function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function validateInput(evt) { var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode( key ); var regex = /[0-9]|\./; if( !regex.test(key) ) { theEvent.returnValue = false; if(theEvent.preventDefault) theEvent.preventDefault(); } } function validate(evt) { if(evt.keyCode!=8) { var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode( key ); var regex = /[0-9]|\./; if( !regex.test(key) ) { theEvent.returnValue = false; if(theEvent.preventDefault) theEvent.preventDefault(); } } }