0

HOW TO CREATE A FORM?

USING ONLINE COMPILER TO FILL THE DATA, SUBMIT THE DATA AND STORE IT IN TABLE? ENTIRELY ONLINE FOR FREE.

28th Sep 2024, 2:29 PM
Aaryan Singh Chauhan
Aaryan Singh Chauhan - avatar
8 Answers
0
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login Form with Table</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="login-container"> <form id="loginForm"> <h2>Login</h2> <div class="input-field"> <label for="username">Username</label> <input type="text" id="username" name="username" required> </div> <div class="input-field"> <label for="password">Password</label> <input type="password" id="password" name="password" required> </div> <button type="submit">Login</button> </form> </div>
28th Sep 2024, 5:14 PM
Ashwin Kumar K
Ashwin Kumar K - avatar
0
Contdd of HTML <div class="table-container"> <h3>Stored Login Data</h3> <table id="dataTable"> <thead> <tr> <th>Username</th> <th>Password</th> </tr> </thead> <tbody> <!-- Data will be appended here --> </tbody> </table> </div> <!-- Move the script here to ensure that the DOM is fully loaded before the script runs --> <script src="script.js"></script> </body> </html>
28th Sep 2024, 5:15 PM
Ashwin Kumar K
Ashwin Kumar K - avatar
0
// script.js document.addEventListener("DOMContentLoaded", function() { document.getElementById("loginForm").addEventListener("submit", function(event) { event.preventDefault(); // Get form values const username = document.getElementById("username").value; const password = document.getElementById("password").value; // Store form data in JSON object const loginData = { username: username, password: password }; // Add the data to the table addToTable(loginData); }); function addToTable(data) { const tableBody = document.querySelector("#dataTable tbody"); // Create a new row const row = document.createElement("tr"); // Create cells for username and password const usernameCell = document.createElement("td"); usernameCell.textContent = data.username;
28th Sep 2024, 5:16 PM
Ashwin Kumar K
Ashwin Kumar K - avatar
0
Contd to JS file const passwordCell = document.createElement("td"); passwordCell.textContent = data.password; // Append the cells to the row row.appendChild(usernameCell); row.appendChild(passwordCell); // Append the row to the table body tableBody.appendChild(row); } });
28th Sep 2024, 5:17 PM
Ashwin Kumar K
Ashwin Kumar K - avatar
0
/* General body styles */ Style. Css body { font-family: Arial, sans-serif; background-color: #f4f4f4; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } /* Container for the login form */ .login-container { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 300px; margin-bottom: 20px; } /* Heading for the login form */ h2 { text-align: center; margin-bottom: 20px; } /* Style for input fields */ .input-field { margin-bottom: 15px; } input[type="text"], input[type="password"] { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; margin-top: 5px; font-size: 16px; } /* Style for the submit button */ button { width: 100%; padding: 10px; background-color: #28a745; color: white; border: none; border-radius: 4px; font-size: 16px; cursor: pointer;
28th Sep 2024, 5:20 PM
Ashwin Kumar K
Ashwin Kumar K - avatar
0
Contdd of CSSS file margin-top: 10px; } button:hover { background-color: #218838; } /* Table container for stored login data */ .table-container { width: 100%; max-width: 600px; margin-top: 20px; } .table-container h3 { text-align: center; margin-bottom: 10px; } /* Table styles */ table { width: 100%; border-collapse: collapse; margin: 0 auto; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } table th, table td { padding: 10px; text-align: left; border: 1px solid #ccc; } table th { background-color: #28a745; color: white; font-weight: bold; text-transform: uppercase; } table tbody tr:nth-child(even) { background-color: #f9f9f9; } table tbody tr:hover { background-color: #f1f1f1; } /* Style the table rows and data cells */ tbody tr td { font-size: 14px; word-wrap: break-word; }
28th Sep 2024, 5:21 PM
Ashwin Kumar K
Ashwin Kumar K - avatar
0
You can add Css file inside style tag and script.js file into the script tag
28th Sep 2024, 5:21 PM
Ashwin Kumar K
Ashwin Kumar K - avatar