This is my HTML and JS code:
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false;
}
}
function validateForm() {
let x = document.forms[myForm][lname].value;
if (x == "") {
alert("Last name should be filled out");
return false;
}
else
alert("Thank you for your response");
}
</script>
</head>
<body>
<h1>Student Information Form</h1>
<br>
<br>
<form name="myForm" onsubmit="return validateForm()" method="post">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="fname"><br> <br>
<label for="email">Email:</label>
<input type="text" id="email" name="email">
<input type="reset">
<input type="submit" value="Submit">
</form>
</body>
</html>
And upon clicking the submit button I’m calling the alert to appear but it’s not appearing. When I have data in the input tags, when I click submit the data just dissapears. Why is this happening???