https://i.sstatic.net/SjxRl.pngI am struggling with this code and despite looking at numerous related questions, I have not found a solution that works. Can someone please assist me? Here are the specific things I need help with:
I need to automatically update the "Amount(USD)" when the value of "Amount(NGN)" is changed. Ideally, I would like to achieve this using Vanilla JS.
Additionally, I want to retrieve the final value of "Amount(USD)", store it in a PHP session, and use it on other pages.
Below is the code snippet I am working with:
<?php $grandTotal=10; ?>
<script type="text/javascript>
function calculateTotal() {
var nairaRate = document.pricecalculator.nairaRateToday.value; //get NGN rate today from admin and assign to nairaRate
dollarValue = eval(document.pricecalculator.nairaInput.value * nairaRate); //multiply nairaInput by nairaRate to get dollarValue
document.getElementById('dollar').innerHTML = dollarValue; //pass dollarValue to dollar to show auto-calculation onscreen
}
</script>
<form name="pricecalculator" action="">
<legend>Price Calculator (Buy BTC)</legend>
<label>Amount (NGN)</label><input type="number" name="nairaInput" onchange="calculateTotal()" value="1" /> <br />
<label>Amount (USD):</label><span id="dollar">1</span> <br />
<input type="hidden" name="nairaRateToday" value="<?= $grandTotal ?>">
</form>