Loading Depth Study
Preparing your workspace
HTML forms provide standard browser controls for collecting user input and submitting data.
Forms are one of the primary ways users send data to web applications. Input elements provide values, labels help users understand fields, and the form submission event lets JavaScript or the browser's default behavior process the data. Applications should validate user input and understand that browser-provided values are not automatically trustworthy.
A registration form may collect a name, email, password, and role before sending the information to a backend API.
<form id="signupForm">
<input name="email" type="email" required />
<button type="submit">Sign Up</button>
</form>
<script>
document.getElementById("signupForm").addEventListener("submit", (event) => {
event.preventDefault();
console.log("Form submitted");
});
</script>The submit event is handled by JavaScript instead of performing the browser's default navigation.