I'm still gripping the ropes of HTML, and I was wondering if you could create a basic form that checks if the entered item is correct, then do something like send an alert or redirect to another page. I already know how to create redirects and alerts but I'm just having trouble with the password part. Thanks in advance.
Unfortunately with the nature of JavaScript the password will always be able to obtained from the source code, unless you link it with a backend API Request.
But here is a very simple example with the password opensesame.
function submitHandler(event) {
const formData = new FormData(event.target);
const password = "opensesame";
if (formData.get("password") === password) {
alert("You're In!");
}
event.preventDefault();
return false;
}
const form = document.getElementById("form");
form.addEventListener("submit", submitHandler);
<form id="form">
<label>Password: <input name="password" type="password"></label>
<br><br>
<button type="submit">Submit form</button>
</form>