d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Just A Minor Error Of Execution And I Cant Figure
Add Reply New Topic New Poll
Member
Posts: 5,253
Joined: Apr 4 2008
Gold: 1.70
Warn: 60%
Oct 16 2012 12:52pm
Okay well I wrote four functions, and two of the four work but I can't seem to get the other two to work although I know my functions are right.

I'm having a problem with the execution of them!

ValidateForm() and Reset() both work
ValidateEmail() and Password checker don't work :/

And I can't seem to figure out why??
Anybody got a quick fix to help me execute this properly,,, its probably something simple and retarded


<head>

<script>
function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>

<script>
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}
</script>

<script>
function checkPwdNumber(pwdNumber)
{
var i
var chr
var errorMsg = "Please enter a Nine Digit Password!"

if (pwdNumber.length != 9)
{
alert(errorMsg)
return false
}

for (i=0; i < pwdNumber.length; i++)
{
chr = pwdNumber.charAt(i)
if (chr > "9" || chr < "0")
{
alert(errorMsg)
return false
}
}

return true
}
</script>

<script type="text/javascript">
function formReset()
{
document.getElementById("myForm").reset();
}
</script>

<script>
function complete_reset()
{
alert("The form has been reset!");
}
</script>

</head>

<body>
<form id="myForm" action="demo_form.asp" name="myForm" onsubmit="return validateEmail();" method="post" onreset="complete_reset()" onSubmit="return checkPwdNumber(this.pwd.value)">
<div class="form_add">First name: <input type="text" name="fname"><br> </div>
<div class="form_add">Last name: <input type="text" name="lastname"><br> </div>
<div class="form_add">Email Address: <input type="text" name="email"><br> </div>
<div class="form_add">Password: <input type="password" name="pwd"><br></div>

<input type="submit" onclick="validateForm()" onclick="validateEmail()" value="Submit"> <br>
<input type="button" onclick="formReset()" value="Reset form"/> <br>
</body>



Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Oct 16 2012 01:32pm
Wrong forum. That's JavaScript, repost it in the Web Languages forum and someone will probably help you out.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll