I'm trying to create a form submission and before the form is submitted, I want to verify the credentials.
I have both this so far
HTML formatted for XHTML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title> Registration Form</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="description" content="This is a form submission with validation"/>
<script type="text/javascript" src="validScript.js"></script>
</head>
<body>
<h1>Registration Form</h1>
<form id="registration" action="" onsubmit="return validation();" method="post" enctype="text/plain">
<p>Name: <input type="text" name="name" id="name"/></p>
<p class="error">Email Address: <input type="text" name="emailAddress" id="emailAddress"/></p>
<p><input type="submit" name="submit" value="Submit"/></p>
</form>
</body>
</html>
JavaScript:
function validation()
{
var vname = document.registration.name;
if(nameValid(vname))
{
return true;
}
return false;
}
function nameValid(vname)
{
var name_len = vname.value.length;
if (name_len == 0)
{
alert("Name is required");
vname.focus();
return false;
}
return true;
}
I'm having issues where it won't display alert the user that he/she prompted an empty name. I'm trying to valid the name and after this I'll add more functions for email address and other fields to be added. Note that this will later be used to email the form to a domain. Can someone help me figure out this problem?
Thanks