Curency Converter
Rates: if the combined total is > 50 then rates are 0.50 and 0.60 otherwise they are 0.58 and 0.60
total euros: €
-.--
Result £
-.--
JavaScript / ECMAScript used in this webpage.
function IsNumeric(sText) {
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
var Dots = 0;
for (i = 0; i < sText.length && IsNumber == true; i++) {
Char = sText.charAt(i);
if (Char == '.') { Dots ++; }
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
if (Dots > 1) {
IsNumber = false;
}
if (sText == ".") {
IsNumber = false;
}
return IsNumber;
}
function calculateEuros() {
var sEurosNotes;
var sEurosCoins;
var flConvRate_Coins;
var flConvRate_Notes;
sEurosNotes = document.getElementById("number_of_euros_notes").value;
sEurosCoins = document.getElementById("number_of_euros_coins").value;
if (!IsNumeric(sEurosNotes)) {
sEurosNotes = 0;
}
if (!IsNumeric(sEurosCoins)) {
sEurosCoins = 0;
}
if (sEurosCoins > 0 || sEurosNotes > 0) {
flConvRate_Coins = 0.58;
flConvRate_Notes = 0.68;
/* Combination Check
if ((sEurosCoins + sEurosNotes) > 50) {
flConvRate_Coins = 0.50;
flConvRate_Notes = 0.60;
}
*/
if (sEurosCoins > 100) {
flConvRate_Coins = 0.60;
}
var num = (sEurosCoins * flConvRate_Coins) + (sEurosNotes * flConvRate_Notes);
document.getElementById("calculation_result").innerHTML = "£ " + num.toFixed(2);
num = (sEurosCoins * 1) + (sEurosNotes * 1);
document.getElementById("euro_input_value").innerHTML = "€ " + num.toFixed(2);
} else {
alert("Sorry, those do not look like valid numbers :-(");
}
return false;
}
