javascript - Calculations in jQuery using keyup() and click() -


i building first app jquery mobile , 1 part of app following :

http://jsfiddle.net/eriky/xbuk2/1/

basically input value, , depending on unit specify, have conversions made in 2 other units.

i have spent lot of time trying different methods can't make work. value appears in first field before user enter own value of field (not present) on page.

could explain me wrong , best way it? better perform calculations when concerned button clicked ?

here code :

$(document).ready(function(){          $("#ex").on("keyup", function() { var val = +this.value || 0; var ghz1 = (2.99792458 * val * 10) ; var nm1 = (ghz1 * math.pow(10,9) * math.pow((532 * math.pow(10,-9)),2) /   (2.99792458*math.pow(10,8)*math.pow(10,-9))); var cm1 = val / (2.99792458  * 10); var nm2 = (val * math.pow(10,9) * math.pow((532 * math.pow(10,-9)),2) / (2.99792458*math.pow(10,8)*math.pow(10,-9))); var cm2 = (val / (2.99792458 * 10)); var ghz2 = 2.99792458 * val * 10; $("#ghz1").val(ghz1.tofixed(2)); $("#nm1").val(nm1.tofixed(2)); $("#cm1").val(cm1.tofixed(2)); $("#nm2").val(nm2.tofixed(2)); $("#cm2").val(cm2.tofixed(2));    $("#ghz2").val(ghz2.tofixed(2));  });  $('#one').click(function() {  $('#one1,#ghz1,#nm1').show();  $('#two2').hide(); $('#three3').hide();    });  $('#two').click(function() { $('#two2,#cm1,#nm1').show();  $('#one1').hide();  $('#three3').hide(); });  $('#three').click(function() { $('#three3,#cm2,#ghz2').show();  $('#one1').hide();  $('#two2').hide(); });    }); 

thanks lot.

your using id selectors # elements don't have id. making them work without ids use selectors $('input[name="ex"]').


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -