Friends,
I am trying to validate my html form using an external javascript but I am getting an error. Here are the code details:
<html>
<head>
<title>Contact US</title>
<link href="StyleSheet.css" rel="Stylesheet" type="text/css" />
<script type = "text/javascript" src = "JavaScript.js"> </script>
</head>
<body>
<h1>Contact Us</h1>
<form id = "contactUs" action="Index.htm" onsubmit = "return validateFirstName()">
<div class="row">
<span class = "label" >First Name:</span>
<span class = "formw"><input type="text" name = "fname"/> </span>
<span class = "formw"><input type="submit" name = "btnSubmit" value = "Submit" /> </span>
</div>
</form>
</body>
</html>
My external javascript file "JavaScript.js" contains the following code:
function validateFirstName() {
var x = document.forms["contactUs"]["fname"].value;
if (x == null || x == "") {
alert("First name cannot be left blank.");
return false;
}
else {
return true;
}
but when I clicked the Submit button then I get the following error:
Line: 19 Error: 'validateFirstName' is undefined
Thank You for your help in advance.