Friday, November 22, 2024

Handle form submission to calculate conversion document.getElementById('currencyForm').addEventListener('submit', function(e) { e.preventDefault(); const fromCurrency = document.getElementById('fromCurrency').value; const toCurrency = document.getElementById('toCurrency').value; const amount = parseFloat(document.getElementById('amount').value); if (isNaN(amount) || amount <= 0) { alert("Please enter a valid amount."); return; } // Example exchange rates - replace with real API data const exchangeRates = { "USD_SAR": 3.75, "USD_EUR": 0.93, "USD_INR": 83.5, "SAR_USD": 0.267, "EUR_USD": 1.075, "INR_USD": 0.012 }; let conversionRate = 1; if (fromCurrency === "USD" && toCurrency === "SAR") { conversionRate = exchangeRates["USD_SAR"]; } else if (fromCurrency === "USD" && toCurrency === "EUR") { conversionRate = exchangeRates["USD_EUR"]; } else if (fromCurrency === "USD" && toCurrency === "INR") { conversionRate = exchangeRates["USD_INR"]; } // Calculate the converted amount const convertedAmount = amount * conversionRate; // Display the result document.getElementById('convertedAmount').textContent = `${convertedAmount.toFixed(2)} ${toCurrency}`; });

Exchange rate

 // Handle form submission to calculate conversion

document.getElementById('currencyForm').addEventListener('submit', function(e) {

    e.preventDefault();


    const fromCurrency = document.getElementById('fromCurrency').value;

    const toCurrency = document.getElementById('toCurrency').value;

    const amount = parseFloat(document.getElementById('amount').value);

    

    if (isNaN(amount) || amount <= 0) {

        alert("Please enter a valid amount.");

        return;

    }


    // Example exchange rates - replace with real API data

    const exchangeRates = {

        "USD_SAR": 3.75,

        "USD_EUR": 0.93,

        "USD_INR": 83.5,

        "SAR_USD": 0.267,

        "EUR_USD": 1.075,

        "INR_USD": 0.012

    };


    let conversionRate = 1;

    if (fromCurrency === "USD" && toCurrency === "SAR") {

        conversionRate = exchangeRates["USD_SAR"];

    } else if (fromCurrency === "USD" && toCurrency === "EUR") {

        conversionRate = exchangeRates["USD_EUR"];

    } else if (fromCurrency === "USD" && toCurrency === "INR") {

        conversionRate = exchangeRates["USD_INR"];

    }


    // Calculate the converted amount

    const convertedAmount = amount * conversionRate;


    // Display the result

    document.getElementById('convertedAmount').textContent = `${convertedAm

ount.toFixed(2)} ${toCurrency}`;

});

How to open a Rajhi bank account in 2025

How to Open an Al Rajhi Bank Account Al Rajhi Bank is one of the largest and most well-known banks in Saudi Arabia. It offers a wide range...