I have a problem.
Can you guys help me to see what wrong with the code because even when I click submit without filling the input text box, nothing happens (there is no alert show up)?
I put the index.html file and javascript file in the same folder, I think there is no problem with the path but I don't know why the doesn't run. Inside the console shows up
"Uncaught TypeError: Cannot read property 'firstName' of undefined at script.js:1"
var getInput=document.forms["signup"]["firstName"];
function check(){
if(getInput.value == ""){
window.alert("Please enter a first name");
getInput.focus();
return false;
}
return true;
}
window.onload=check;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sign up</title>
<script src="./javascript/script.js"></script>
</head>
<body>
<form name="signup" action="#" method="post" onsubmit="return check()">
<label for="inputFirstName">First name</label>
<input type="text" id="inputFirstName" value="" name="firstName">
<input type="submit" value="Click Me">
</form>
</body>
</html>