• 30-11-2021, 11:25:21
    #1
    Merhaba,

    Elimde aşağıdaki gibi bir kod bloğu bulunmakta. Ben bu kodlardan 1.inputa girilen sayının 2.inputa eş zamanlı olarak (aynı anda) dolara çevrilmiş halini yazdırmak istiyorum fakat yapamadım.

    Yardımcı olabilecek arkadaşlara şimdiden teşekkür ederim.

    <?php
    
    $xml = simplexml_load_file('http://www.tcmb.gov.tr/kurlar/today.xml');
    foreach ($xml->Currency as $Currency) {
        
        if ($Currency['Kod'] == "USD") {
            $usd_ES = $Currency->ForexSelling;
            $usd_EA = $Currency->ForexBuying;
        }
    }
    
    function dolar_to_tl($a) {
        global $usd_ES;
        $a = strtr($a, ',', '.');
        $b = strtr($usd_ES, ',', '.');
        $ret = $a * $b;
        return strtr($ret, '.', ',');
       }  
    
    echo "100 Dolar ".dolar_to_tl("100")." TL dir.";
    
    ?>
    
    
    <script>
    function add_number(e) {
      if (isNumberKey(e)) {
        setTimeout(() => {
          var first_number = document.getElementById("Text1").value !== "" ? parseInt(document.getElementById("Text1").value) : 0;
          var result = first_number;
          document.getElementById("txtresult").value = result;
        }, 50)
        return true;
      } else {
        return false;
      }
    }
    
    function isNumberKey(evt) {
      var charCode = (evt.which) ? evt.which : event.keyCode
      if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
      }
      return true;
    }
    </script>
    
    <p>TL : <input type="text" id="Text1" name="TextBox1" onkeypress="return add_number(event)"></p>
    
    <br>Dolar: <input type="text" id="txtresult" name="TextBox3">
  • 30-11-2021, 11:49:00
    #2
    PHP - WORDPRESS - YAZILIM
    Şöyle bir çözüm ürettim.

    1 ) index.php

    <p>TL : <input type="text" id="Text1" name="TextBox1"></p>
     
    <br>Dolar: <input type="text" id="txtresult" name="TextBox3">
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    
    <script>
    
        $("#Text1").on("change keyup", function(e) {
    
            var tl = $(this).val();
            $.ajax({
                type: "POST",
                url: "/dolar-result.php",
                data: { tl: tl },
                success: function (x) {
                    $('#txtresult').val(x)
                },
            });
    
        });
    
    </script>
    2 ) dolar-result.php

    <?php
    
    
        $xml = simplexml_load_file('http://www.tcmb.gov.tr/kurlar/today.xml');
        foreach ($xml->Currency as $Currency) {
             
            if ($Currency['Kod'] == "USD") {
                $usd_ES = $Currency->ForexSelling;
                $usd_EA = $Currency->ForexBuying;
            }
        }
    
    
        function dolar_to_tl($a) {
            global $usd_ES;
            $a = strtr($a, ',', '.');
            $b = strtr($usd_ES, ',', '.');
            $ret = $a * $b;
            return strtr($ret, '.', ',');
           }  
         
        echo dolar_to_tl($_POST['tl']);
     
    
    ?>
    bu şekilde sorunsuz çalışmakta ama geliştirmen gerekebilir, ben şimdi var olan kod yapısını bozmadan basitçe bir düzenleme yapmaya çalıştım.
  • 30-11-2021, 11:49:18
    #3
    Çözülmüştür. İlgi alakanıza teşekkür ederim.


    metin_nn adlı üyeden alıntı: mesajı görüntüle
    Şöyle bir çözüm ürettim.

    1 ) index.php

    <p>TL : <input type="text" id="Text1" name="TextBox1"></p>
     
    <br>Dolar: <input type="text" id="txtresult" name="TextBox3">
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    
    <script>
    
        $("#Text1").on("change keyup", function(e) {
    
            var tl = $(this).val();
            $.ajax({
                type: "POST",
                url: "/dolar-result.php",
                data: { tl: tl },
                success: function (x) {
                    $('#txtresult').val(x)
                },
            });
    
        });
    
    </script>
    2 ) dolar-result.php

    <?php
    
    
        $xml = simplexml_load_file('http://www.tcmb.gov.tr/kurlar/today.xml');
        foreach ($xml->Currency as $Currency) {
            
            if ($Currency['Kod'] == "USD") {
                $usd_ES = $Currency->ForexSelling;
                $usd_EA = $Currency->ForexBuying;
            }
        }
    
    
        function dolar_to_tl($a) {
            global $usd_ES;
            $a = strtr($a, ',', '.');
            $b = strtr($usd_ES, ',', '.');
            $ret = $a * $b;
            return strtr($ret, '.', ',');
           }  
        
        echo dolar_to_tl($_POST['tl']);
     
    
    ?>
    bu şekilde sorunsuz çalışmakta ama geliştirmen gerekebilir, ben şimdi var olan kod yapısını bozmadan basitçe bir düzenleme yapmaya çalıştım.