I'm facing an issue with my validation code. It doesn't seem to be working correctly.
The two things I'm trying to validate are:
- Check if any textfield is empty
- Ensure that the password field has a minimum of 8 characters
If either one of these conditions fails, an error message should be displayed. However, the error message isn't showing up when it should. Here's the snippet:
function validate() {
if (document.getElementById("name").value == '') {
document.getElementById("errorMsg").innerHTML = "You have forgotten to enter your name";
}
else if (document.getElementById("surname").value == '') {
document.getElementById("errorMsg").innerHTML = "You have forgotten to enter your surname";
}
else if (document.getElementById("email").value == '') {
document.getElementById("errorMsg").innerHTML = "You have forgotten to enter your email address";
}
}
* {
margin: 0px;
padding: 0px;
}
#title{
font: bold 20px Tahoma;
color: white;
margin: 10px;
text-align: left;
width: 80%;
}
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fastloader - Register for a new account</title>
<link rel="stylesheet" href="register.css">
<script src="register.js"></script>
</head>
<body>
<div id = "main-container">
<header id = "header">
<h1>Register for a new account<h1>
</header>
<div id= "control-container">
<section id ="label-container">
<p><label>Enter your Name:</label></p>
<p><label>Enter your Surname:</label></p>
<p><label>Enter your Email address:</label></p>
<p><label>Choose a strong Password:</label></p>
</section>
<status id = "element-container">
...
... // Rest of the HTML content