JavaScript - 21
JavaScript - 21: Form Handling
Create a simple form with name and age inputs. When the user clicks "Submit", show a personalized message below using the values they entered.
👀 Show Solution
const form = document.getElementById("userForm");
const result = document.getElementById("result");
form.addEventListener("submit", function(e) {
e.preventDefault();
const name = document.getElementById("name").value;
const age = document.getElementById("age").value;
result.textContent = \`Hello \${name}! You are \${age} years old.\`;
});