Trying To Get Currency Converter To Work Using Jquery
I'm working on a project using jQuery to make a currency converter. I'm getting the currency info from an api service and loading it up in a table with multiple currencies. After w
Solution 1:
That's a bit strange for me, because you select all the input field which are NOT focused, and in the keyup eventhandler you just work with the inputValue variable, which contains the focused input element too. By the way, you shouldn't iterate two times on the data.results. As charlietfl commented before it does not make any sense to put the bindings to the iteration. That's a big mistake also.
Solution 2:
A simple Method
<html><head><scriptsrc="https://code.jquery.com/jquery-3.3.1.min.js"></script><script>functionchangeTo(toType){
if(toType=="Pound")
cvrate = 0.86;
else
cvrate = 0.78;
$(".currency_change").each(function (index, element) {
var og_val = $(this).data("og-value");
var cvd_val = (og_val*cvrate).toFixed(2);
return $(this).html(cvd_val);
});
}
</script></head><body><br /><spanclass="currency_change"data-og-value="1254">1254</span><br /><spanclass="currency_change"data-og-value="145">145</span><br /><spanclass="currency_change"data-og-value="54">54</span><br /><spanclass="currency_change"data-og-value="254">254</span><br /><spanclass="currency_change"data-og-value="147">147</span><br /><buttononClick="changeTo('Pound');">Conver To Pound</button><buttononClick="changeTo('Euro');">Conver To Euro</button></body></html>
Post a Comment for "Trying To Get Currency Converter To Work Using Jquery"