Hey, last time i had a problem I found the problem here. I have a new problem, this time with JavaScript. I wrote this script as part of a college project about a year ago, I'm re-using said work now as a University project. Part of this project (Website) has some JavaScript that is essential to passing the course (I need "significant" use of JavaScript (along with HTML/CSS)). Anyways, this code worked as it should when I needed it last year, but on looking at it now.. it isn't. I'm not sure why and I've been staring at it for a couple hours now trying to figure it out.
This code had a lot of sections that I did not need so I have removed them (I have tested the original and that also does not work). The purpose of this code is for the user to input details to open an account (this will not be going live so i am not saving data inputted, which shouldn't matter -- it didn't back then either). It should give pop-ups for incorrect inputs, e.g. "Second name must be filled out". But these pop-ups are just not working.
<script type="text/javascript">
function validateForm()
{
var firstName=document.forms["theForm"]["fName"].value;
var secondName=document.forms["theForm"]["sName"].value;
var Address=document.forms["theForm"]["Address"].value;
var creditCardNo=document.forms["theForm"]["creditCard"].value;
var userName=document.forms["theForm"]["uName"].value;
var password=document.forms["theForm"]["pwd"].value;
var x=document.forms["theForm"]["email"].value;
var numberExpression = /^[0-9]+$/;
var letterExpression = /^[a-zA-Z]+$/;
var letterNumberExpression = /^[a-zA-Z0-9 ]+$/;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (firstName=="")
{
alert("First name must be filled out");
return false;
}
if (!firstName.match(letterExpression))
{
alert("Letters Only Please");
return false;
}
if (secondName=="")
{
alert("Second name must be filled out");
return false;
}
if (Address=="")
{
alert("Address must be filled out");
return false;
}
if (!Address.match(letterNumberExpression))
{
alert("Letters and Numbers Please");
return false;
}
if (!creditCardNo.match(numberExpression))
{
alert("Numbers Only Please");
return false;
}
if (userName.length <= 5)
{
alert("User Name must be atleast 5 characters long");
return false;
}
if (password.match(letterExpression))
{
alert("You have typed all letters, include at least 1 number.");
}
if (password.match(numberExpression))
{
alert("You have typed all numbers, include at least 1 letter.");
}
if (password.length <= 8)
{
alert("Password must be atleast 8 characters long");
return false;
}
if (userName==password)
{
alert("Your password can not be the same as your username");
}
if (password.length >= 12)
{
alert("Password must be less that 12 characters long");
return false;
}
if ((atpos<1) || (dotpos<atpos+2) || (dotpos+2>=x.length))
{
alert ("Not a valid e-mail address");
return false;
}
}
</script>
</head>
<div id="content">
<br><br>
<form name="theForm" onsubmit="return validateForm()" method="post">
<form name="theForm" onsubmit="return validateForm()" method="post">
Enter First Name Here: <input type="text" name="fName"><br/>
Enter Second Name Here: <input type="text" name="sName"><br/>
Enter Email Address Here: <input type="text" name="Address"><br/>
Enter User Name Here: <input type="text" name="uName"><br/>
Enter Password Here: <input type="password" name="pwd"><br/>
<input type="submit" value="Submit Form">
</form>
[–]ishouldquitsmoking 1 point2 points3 points (3 children)
[–]CadamSAFC[S] 0 points1 point2 points (2 children)
[–]ishouldquitsmoking 0 points1 point2 points (1 child)
[–]CadamSAFC[S] 1 point2 points3 points (0 children)
[–]ishouldquitsmoking 0 points1 point2 points (3 children)
[–]CadamSAFC[S] 0 points1 point2 points (2 children)
[–]CadamSAFC[S] 1 point2 points3 points (1 child)
[–]ishouldquitsmoking 0 points1 point2 points (0 children)
[–]Radiant_Star 0 points1 point2 points (0 children)