Why does this code say to fill in all values when all the fields are filled? It should only give the "fill in all fields" message when they are actually empty.
<html>
<head>
<title>javascript</title>
</head>
<body>
<h1>test page</h1>
<hr>
<script type="text/javascript">
function checkForm(form) {
for(var i = 0; i<form.elements.length; i++) {
if(form.elements[i].value == "") {
alert("Please fill out all fields.");
return false;
}
}
return true;
}
</script>
<form onSubmit="return checkForm(this)">
<input type="text" name="firstName"><br>
<input type="text" name="lastName">
<input type="submit">
</form>
</body>
</html>