JSFiddle - React, Tailwind, and code Playground

by mrcl

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>iTunes Apps by Developer ID</title>
  <style>
    table {
      border-collapse: collapse;
      width: 100%;
    }
    th, td {
      border: 1px solid #ddd;
      padding: 8px;
    }
    th {
      background-color: #f4f4f4;
    }
  </style>
</head>
<body>
  <h1>Fetch Apps by Developer ID</h1>
  <form id="searchForm">
    <label for="developerId">Developer ID:</label>
    <input type="text" id="developerId" placeholder="Enter iTunes Developer ID">
    <button type="submit">Fetch Apps</button>
  </form>
  <br>
  <table id="resultsTable">
    <thead>
      <tr>
        <th>Seller Name</th>
        <th>App Name</th>
        <th>Bundle ID</th>
        <th>Primary Genre</th>
      </tr>
    </thead>
    <tbody>
    </tbody>
  </table>

  <script>
    const form = document.getElementById('searchForm');
    const resultsTableBody = document.querySelector('#resultsTable tbody');

    form.addEventListener('submit', async (event) => {
      event.preventDefault();

      const developerId = document.getElementById('developerId').value.trim();
      if (!developerId) {
        alert('Please enter a Developer ID');
        return;
      }

      // Clear previous results
      resultsTableBody.innerHTML = '';

      const url = `https://itunes.apple.com/lookup?id=${developerId}&entity=software`;

      try {
        const response = await fetch(url);
        if (!response.ok) {
          throw new Error('Failed to fetch data from iTunes API');
        }

        const data = await response.json();
        const results = data.results;

        if (results.length === 0) {
          alert('No results found for this Developer ID');
          return;
        }

        // Populate the table with results
        results.slice(1).forEach(result => {
          const row = document.createElement('tr');
          row.innerHTML = `
     ...