Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I write a javascript version. no Ajax, currency change rates was borrowed from google.</p> <p><strong>HTML Code</strong></p> <pre><code> &lt;select id="currencySelector"&gt; &lt;option value="usd"&gt;USD&lt;/option&gt; &lt;option value="aud"&gt;AUD&lt;/option&gt; &lt;option value="eur"&gt;EUR&lt;/option&gt; &lt;option value="gbp"&gt;GBP&lt;/option&gt; &lt;/select&gt; &lt;div class="currency" data-currencyName="usd"&gt;15&lt;span&gt;USD&lt;/span&gt;&lt;/div&gt; &lt;div class="currency" data-currencyName="eur"&gt;15&lt;span&gt;EUR&lt;/span&gt;&lt;/div&gt; &lt;div class="currency" data-currencyName="gbp"&gt;15&lt;span&gt;BGP&lt;/span&gt;&lt;/div&gt; &lt;div class="currency" data-currencyName="aud"&gt;15&lt;span&gt;AUD&lt;/span&gt;&lt;/div&gt; </code></pre> <p><strong>Javascript Code</strong></p> <pre><code>var selector = document.getElementById("currencySelector"); var currencyElements = document.getElementsByClassName("currency"); var usdChangeRate = { AUD: 1.0490, // 1AUD = 1.0490 USD EUR: 1.4407, // 1EUR = 1.4407 USD GBP: 1.6424, USD: 1.0 }; selector.onchange = function () { var toCurrency = selector.value.toUpperCase(); for (var i=0,l=currencyElements.length; i&lt;l; ++i) { var el = currencyElements[i]; var fromCurrency = el.getAttribute("data-currencyName").toUpperCase(); if (fromCurrency in usdChangeRate) { var // currency change to usd fromCurrencyToUsdAmount = parseFloat(el.innerHTML) * usdChangeRate[fromCurrency]; var // change to currency unit selected toCurrenyAmount = fromCurrencyToUsdAmount / usdChangeRate[toCurrency]; el.innerHTML = toCurrenyAmount + "&lt;span&gt;" + toCurrency.toUpperCase() + "&lt;/span&gt;"; el.setAttribute("data-currencyName",toCurrency); } } }; </code></pre> <p><strong>Run the code</strong></p> <p>You can run the code above at <a href="http://jsbin.com/ewuyoq/5" rel="nofollow">http://jsbin.com/ewuyoq/5</a> or build your own version <a href="http://jsbin.com/ewuyoq/5/edit" rel="nofollow">http://jsbin.com/ewuyoq/5/edit</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload