Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Aplikasi CRUD</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <style>
    .container {
  max-width: 650px;
  margin: 20px auto;
  padding: 20px;
  background-color: #F2F4F4;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  </style>
</head>

<body>
  <div class="container">
    <h2>Aplikasi CRUD</h2>

    <form id="form-data">
      <div class="form-group">
        <label for="nama">Nama:</label>
        <input type="text" class="form-control" id="nama" required>
      </div>
      <div class="form-group">
        <label for="email">Email:</label>
        <input type="email" class="form-control" id="email" required>
      </div>
      <button type="submit" class="btn btn-primary">Tambah</button>
    </form>

    <table class="table mt-4">
      <thead>
        <tr>
          <th>Nama</th>
          <th>Email</th>
          <th>Aksi</th>
        </tr>
      </thead>
      <tbody id="data-table">
        <!-- Data akan ditambahkan secara dinamis menggunakan JavaScript -->
      </tbody>
    </table>
  </div>

  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  <script>
    // Fungsi untuk menambahkan data ke tabel
    function tambahData() {
      var nama = document.getElementById('nama').value;
      var email = document.getElementById('email').value;

      var row = '<tr>' +
        '<td>' + nama + '</td>' +
        '<td>' + email + '</td>' +
        '<td>' +
        '<button class="btn btn-sm btn-primary" onclick="editData(this)">Edit</button> ' +
        '<button class="btn btn-sm btn-danger" onclick="hapusData(this)">Hapus</button>' +
        '</td>' +
        '</tr>';

      document.getElementById('data-table').innerHTML += row;

      // Reset form setelah data ditambahkan
      document.getElementById('form-data').reset();
    }

    // Fungsi untuk mengedit data
    function editData(button) {
      var row = button.parentNode.parentNode;
      var nama = row.cells[0].innerHTML;
      var email = row.cells[1].innerHTML;

      document.getElementById('nama').value = nama;
      document.getElementById('email').value = email;

      // Hapus baris setelah data diambil untuk diedit
      row.remove();
    }

    // Fungsi untuk menghapus data
    function hapusData(button) {
      var row = button.parentNode.parentNode;
      row.remove();
    }

    // Event listener untuk form submit
    document.getElementById('form-data').addEventListener('submit', function (e) {
      e.preventDefault();
      tambahData();
    });
  </script>
</body>

</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console