Converting the entered currency amounts when I change the currency

Hello,
When I change the currency with the Select option option, I want the coins just below to be converted

Ekran görüntüsü 2022-08-02 112751

<select size="1" name="currency">
<option selected value="USD">USD</option>
<option value="EURO">EURO</option>
<option value="TRY">TRY</option>
</select>

<input type="text" name="" value="320.50">
<input type="text" name="" value="150.00">
<input type="text" name="" value="250.35">

Exchange rates available with php

$usd = 17.9846; //TRY  
$euro = 18.4251; //TRY  
$euro_usd = 1.0245; //USD

I want it to convert without refreshing the page
Page is not refreshed
USD to TRY,
TRY to EURO,
USD to EURO,
EUR to TRY
as
I will be glad if you help

I adapted the code I found above for myself and got results.
I don’t know how right I did

$('#secilen_parabirimi').change(function(){
var oldvar = $(this).attr('data-old') !== typeof undefined? $(this).attr('data-old') :"";
var newval = $("option:selected",this).text();
$(this).attr('data-old',newval)

var ucret = $("#ucret").val();

var usd = '17.9846';
var euro = '18.4251';
var usd_euro = '1.0245';

if(oldvar!==undefined){ // So that the page does not convert money while loading
  if(oldvar==='USD' && newval==='TRY'){
    $("#ucret").val((usd*ucret).toFixed(2));
  }
  if(oldvar==='USD' && newval==='EURO'){
    $("#ucret").val((ucret/usd_euro).toFixed(2));
  }
  if(oldvar==='EURO' && newval==='TRY'){
    $("#ucret").val((euro*ucret).toFixed(2));
  }
  if(oldvar==='EURO' && newval==='USD'){
    $("#ucret").val((ucret*usd_euro).toFixed(2));
  }
  if(oldvar==='TRY' && newval==='EURO'){
    $("#ucret").val((ucret/euro).toFixed(2));
  }
  if(oldvar==='TRY' && newval==='USD'){
    $("#ucret").val((ucret/usd).toFixed(2));
  }
}

}).change();

There is only one problem.
When converting multiple times in a row, the result increases by odds due to rounding
Sample:
830.00 => 830.75, 830.01 as

Sponsor our Newsletter | Privacy Policy | Terms of Service