Your scripts are running before the DOM loads, and you are trying to access DOM Elements in those scripts.
If you don’t know what DOM is Google it.
The solution is to run scripts on load event of Document.
document.onload = function(){
//Your code here.
...
}
The validateForm
works because you are just defining function and not accessing DOM directly.
solved Why aren’t both of my scripts in html working?