javascript - Changing the value of an input from another input on keyup using jQuery -



javascript - Changing the value of an input from another input on keyup using jQuery -

i have 2 inputs set simultaneously convert lbs kgs , kgs lbs on keyup depending on input use. have error function run if input not number. conversion works both inputs on keyup , error well, initially, if clear inputs or switch 1 , lose error function , clear function doesn't clear input in sec one, leaves number, 0.00. using jquery plugin, jquery number round numbers 2 places.

here jsfiddle , code:

$(document).ready(function () { var kg = 0.453 $('#weight_lb').on('keyup', function () { var wtvaluel = parsefloat($('#weight_lb').val()); if (!isnan(wtvaluel)) { $("#weight_kg").val($("#weight_lb").val() * kg).number(true, 2); } else { // input wasn't number $('#weight_lb').val(''); $(".wt_error").fadein(); settimeout(function () { $(".wt_error").fadeout(); }, 2000); homecoming false; } }); $('#weight_kg').on('keyup', function () { var wtvaluek = parsefloat($('#weight_kg').val()); if (!isnan(wtvaluek)) { $("#weight_lb").val($("#weight_kg").val() / kg).number(true, 2); } else { // input wasn't number $('#weight_kg').val(''); $(".wt_error").fadein(); settimeout(function () { $(".wt_error").fadeout(); }, 2000); homecoming false; } }); $(".clear").on('click', function () { $("#weight_lb").val("").attr('placeholder', 'enter weight'); $("#weight_kg").val("").attr('placeholder', 'enter weight'); }); });

javascript jquery function user-input

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -