Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 10th, 2004, 11:25 AM
Sweety_oh Sweety_oh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 23 Sweety_oh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Javascript onBlur error

Hi I have a form to register new user in which i ask them to enter their passwords twice. I want them to enter passwords greater than or equal to six characters and also they should enter same password, but if they don't then the onBlur function should give appropiate messages to the user. I have written the following code but it is not working can anyone of you help me with this code.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Registration Form for New User</title>
<style type="text/css">
<!--
.style1 {
font-family: "Monotype Corsiva";
font-weight: bold;
}
.style2 {font-family: "Monotype Corsiva"}
body {
background-image: url();
}
-->
</style>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function validate(new_user)
{
if ( isName() && isDept() && isBuild() && isEmail() && isPhone())
{
document.forms[0].action = "new_user.asp";document.forms[0].submit();
}
return true;
}
//Name validator
function isName(new_user)
{
var str = document.forms[0].username.value;
if (str == "")
{
alert("\nThe Name field is blank .\n\nPlease re-enter your Name.");

document.forms[0].username.focus();
return false;
}
if((str.substring(0,1)<"a" || str.substring(0,1)>"z") && (str.substring(0,1)<"A" ||
str.substring(0,1)>"Z"))
{
alert("The Name should begin with an alphabetic character.");
document.forms[0].username.select();
return false;
}
for (var i = 1; i < str.length; i++)
{
var ch = str.substring(i, i + 1);
if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch)
&& (ch != ''))
{
alert("\nThe Name field accepts letters,numbers & underscore
only.\n\nPlease re-enter your Name.");
document.forms[0].username.select();
document.forms[0].username.focus();
return false;
}
}

return true;
}
// Department Validator
function isDept(new_user)
{
var str = document.forms[0].department.value;
if (str == "")
{
alert("\nThe Department field is blank .\n\nPlease re-enter your Department.");
document.forms[0].department.select();
document.forms[0].department.focus();
return false;
}

return true;
}
// Building Validator
function isBuild(new_user)
{
var str = document.forms[0].building.value;
if (str == "")
{
alert("\nThe Building field is blank .\n\nPlease re-enter your Building.");
document.forms[0].building.select();
document.forms[0].building.focus();
return false;
}

return true;
}

// Email Address Validator
function isEmail(new_user)
{
var str = document.forms[0].email.value;
if (str == "")
{
alert("\nThe Email Address field is blank .\n\nPlease re-enter your Email
Address.");
document.forms[0].email.select();
document.forms[0].email.focus();
return false;
}

return true;
}

// Phone Validator
function isPhone(new_user)
{
var str = document.forms[0].phone.value;
if (str == "")
{
alert("\nThe Phone field is blank .\n\nPlease re-enter your Phone Number.");
document.forms[0].phone.select();
document.forms[0].phone.focus();
return false;
}

return true;
}

// Password Validator
function isPass(new_user)
{
var str = document.new_user.password.value;
if ((str == "") || (str.length < 6))
{
alert("\nThe PASSWORD field is either empty or less than 6 characters.\n\nPlease
re-enter your Password.")
document.new_user.password.focus();

return false;
}
var str1 = document.new_user.password1.value;
if (str != str1)
{
alert("Passwords typed do not match, please re-enter your passwords.\n\n");
document.new_user.password.select();
document.new_user.password.focus();
document.new_user.password1.select();
document.new_user.password1.focus();
return false;
}
return true;
}

</SCRIPT>
</head>
<body onLoad="window.document.new_user.username.focus();" >
<center>
<form name="new_user" method="post" >

<table width="50%" border="1" align="center" cellpadding="0.5" cellspacing="0.5">
<tr>
<td width="391"><h1 align="center" class="style1"><img src="register.gif" height=100
width=150></h1>
<br>
<br>
<h4 align="center"><font color="red"><b><i>All fields marked with</i> * <i>are
mandatory</i> </b></font></h4>
<table name="userdetails" align="center" cellspacing=5 cellpadding=5>
<tr align="left">
<td><span class="style2">Username:</span></td>
<td><input type="text" name="username"><font color="red">*</font></td>
</tr>
<tr align="left">
<td><span class="style2">Password:</span></td>
<td><input type="password" name="userpassword"><font color="red">*</font></td>
</tr>
<tr align="left">
<td><span class="style2">Retype Password:</span></td>
<td><input type="password" name="userpassword1" onBlur="return isPass(new_user)"><font
color="red">*</font></td>
</tr>
<tr align="left">
<td></td>
<td><span class="style2"><font color="red">Password must be at least 6 characters long.
It may contain alphabets A-Z, or a-z, numbers 0-9 and underscore but no spaces and special
characters.</font></span></td>
</tr>
<tr align="left">
<td><span class="style2">Room Number:</span></td>
<td><input type="text" name="roomno"></td>
</tr>
<tr align="left">
<td><span class="style2">Department:</span></td>
<td><input type="text" name="department"><font color="red">*</font></td>
</tr>
<tr align="left">
<td><span class="style2">Building:</span></td>
<td><input type="text" name="building"><font color="red">*</font></td>
</tr>
<tr align="left">
<td><span class="style2">E-mail:</span></td>
<td><input type="text" name="email"><font color="red">*</font></td>
</tr>
<tr align="left">
<td><span class="style2">Phone Number:</span></td>
<td><input type="text" name="phone"><font color="red">*</font></td>
</tr>
</table>
<p><br>
<br>
<input type="button" align="absmiddle" value="REGISTER ME" onclick="return validate()">
<input type="reset" align="absmiddle" value="CLEAR FORM">
</p>
<p>&nbsp; </p></td>
</tr>
</table>
<br>
</form>
</center>
<br>
<br>
</body>
</html>

Reply With Quote
  #2  
Old June 10th, 2004, 12:09 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
There were a couple of issues with your code.
Here is an example
Code:
<script language="JavaScript">
function validatePasswords() 
{
	var pass1 = document.forms[0].password1.value;
	var pass2 = document.forms[0].password2.value;
	
	// Validate the first password field
	if (pass1 == '' || pass1.length < 6) 
	{
		alert("\nThe FIRST PASSWORD field is either empty or less than 6 characters.\n\nPlease re-enter first password.");
		document.forms[0].password1.select();
		document.forms[0].password1.focus();

		return false;
	}
	
	if(pass2 == '' || pass2.length < 6)
	{
		alert("\nThe SECOND PASSWORD field is either empty or is less than 6 characters.\n\nPlease re-enter the second password.");
		document.forms[0].password2.select();
		document.forms[0].password2.focus();
		
		return false;
	}

	if (pass2 != pass1)
	{
		alert("Your passwords do not match, please verify you entered the same password in each field.\n\n");
		document.forms[0].password1.select();
		document.forms[0].password1.focus();
		return false;
	}
	
	return true;
}
</script>
<form name="form1">
<table>
<tr align="left">
<td><span class="style2">Password:</span></td>
<td><input type="password" name="password1"><font color="red">*</font></td>
</tr>
<tr align="left">
<td><span class="style2">Retype Password:</span></td>
<td><input type="password" name="password2" onBlur="return validatePasswords()"><font 
color="red">*</font></td>
</tr>
</table>
</form>

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Javascript onBlur error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway