lundi 26 janvier 2015

Javascript .onchange?

I am currently trying to find out a way to automatically store the previous price of an item before it gets updated. For instance, if on my website I show the currency exchanges let it be USD to EURO and I only get the real time exhange price, how can I use javascript to display the previous value in one line and display the updated value in another line. This is an example code, assuming that the random number is the exchange price between the currencies.


Markup:



<p id="price"></p>
<p id="previous"></p>


JavaScript:



<script>
var price = Math.round((Math.random() + 1)*100)/100;
document.getElementById("price").innerHTML = price;
</script>


In this case scenario, a random number appears and it is for example 1.11. Afterwards, I refresh the page, the script runs again and the random number changes to 1.43. I want to display the new random number which is 1.43 under #price and the old (or previous) random number which in this case was 1.11 under #previous. How can I use JavaScript to do so?





Aucun commentaire:

Enregistrer un commentaire