r/learnjavascript • u/Successful-Throat621 • 23d ago
Simple Password input field
Hi all, I've been learning webcoding recently and Ive been wanting to make a website to use as a prop in my tabletop games.
My biggest desire right now is to do a password input where submitting an incorrect input displays an error message, while the correct input provides a redirect to a new page.
Since this will only be for my friends and wont host any private data, I'm not too concerned for heavy security, but most resources online are for actual websites and online security. Whats the best way for me to implement something like this?
View all comments
1
u/Alternative-Host-210 20d ago
About the example you couldn't get running: its script has been squeezed onto one line, including comments starting with //. In JavaScript, // comments out everything until the next line break, so the first comment can accidentally hide the rest of that script.
Start with the shorter example above that uses a form submit listener. Keep the script after the form, and put each statement on its own line. Test a wrong word first, then the correct word, then submitting with Enter.
If it still fails, paste your current HTML and the first red error from the browser console here. That will make it much easier to identify the exact problem than adding another full version of the code.