0
<?php
$currency = file_get_contents('https://api.pro.coinbase.com/currencies');
$result = json_decode($currency);
$totalCurrency = array();
foreach($result as $key){
  if($key->details->type == 'crypto'){
    array_push($totalCurrency, $key);
  }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Aditya Dev ~~ Coinbase Deposit By PHP</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
    <div class="main">
        <div class="dropdown">
            <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown button
            </button>
            <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
              <?php foreach($totalCurrency as $key): ?>
                <li><a class="dropdown-item" href="#"><?= $key->id; ?></a></li>
              <?php endforeach; ?>
            </ul>
          </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
    <script src="index.js"></script>
</body>
</html>

In the PHP I fetch all crypto coin symbols from API and store it Here in this line $totalCurrency = array(); and then I run a loop to create a dropdown list like this enter image description here

I want that if I click any currency from there javascript send an alert like this alert(symbol)

I am quite confused about how to do this, it's not a button its tag, please help me

Aditya Dev
  • 100
  • 1
  • 8

0 Answers0