0

What's wrong?

HTML <form action="scripts/author.js" onsubmit="submit(this)"> <input type="text" id="name" class="auto-input" style="margin-top: 30px;" /> <input type="submit" id="auto-submit" /> </form> JS <script type="text/javascript"> var x = getElementById="name"; var pass = x.value; var rPass = 10; function submit(form) { if (pass == rPass) alert('right!'); else alert('try again!'); } </script>

22nd Dec 2016, 11:51 AM
Hutsko
Hutsko - avatar
1 Answer
+ 1
You can't call a JS script with a form submit, it need a server call ( like another page loading -- ie: often a PHP script / or for executing JS server side you need NodeJS on it ). If you want to test the values of your form before sending them, you use JS, but linked to the HTML ( ie: script is visible, instead of when executing server sided scripts, so it's not a good way to test a password :P )
22nd Dec 2016, 12:02 PM
visph
visph - avatar