c# - I want to create a jquery for conversion of gold to amount and vice versa -


problem description : want create jquery method can convert gold weight amount multiplying gold rate f.e 50*2000=100000 , vice versa amount gold dividing gold rate f.e 100000/2000=50

amount=goldweight*goldrate; // top down approach goldweight=amount/goldrate; // bottom approach 

but @ same if textbox have values should convert gold if change amount , amount if change in gold value....please me in this..

this answer

$(document).ready(function() {    $('#txtgoldconverted').focusin(function() {     var r = $('#txtamount').val();     var q = $('#txtgoldrate').val();     if (r != "" && q != "") {       var p = r / q;       var res = p.tofixed(3);       var resround = (math.round(res * 100)) / 100;       $('#txtgoldconverted').val(resround);     }   });    $('#txtgoldconverted').focusout(function() {     var p = $('#txtgoldconverted').val();     var q = $('#txtgoldrate').val();     if (p != "" && q != "") {       var r = p * q;       $('#txtamount').val(r);     }    });    $('#txtgoldrate').focusout(function() {     var p = $('#txtgoldconverted').val();     var q = $('#txtgoldrate').val();     var r = p * q;     $('#txtamount').val(r);   });    $('#txtamount').focusin(function() {     var p = $('#txtgoldconverted').val();     var q = $('#txtgoldrate').val();     if (p != "" && q != "") {       var r = p * q;       $('#txtamount').val(r);     }   });    $('#txtamount').focusout(function() {     var r = $('#txtamount').val();     var q = $('#txtgoldrate').val();     if (r != "" && q != "") {       var p = r / q;       var res = p.tofixed(3);       var resround = (math.round(res * 100)) / 100;       $('#txtgoldconverted').val(res);     }   }); }); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -