Why does my code under JavaScript won't work if I try to write it under HTML?
<html> <head> <title>Form</title> </head> <body> <form onsubmit="return validate()" method="post"> Number: <input type="text" name="num1" id="num1" /><br /> Repeat: <input type="text" name="num2" id="num2" /><br /> <input type="submit" value="Submit" /> </form> <script> function validate() { var n1= document.getElementById("num1"); var n2= document.getElementById("num2"); if (n1.value!="" && n2.value!="") { if (n1.value == n2.value) { return true; } } alert("The values must be equal and not blank); return false; } </script> </body> </html> That's how I did it. I added the script tag under the body, and that's where I wrote my code for JavaScript. It works in the Code Playground, but when I tried to do it on my notepad it doesn't work :<