Wrox Programmer Forums
|
BOOK: Beginning HTML, XHTML, CSS, and JavaScript
This is the forum to discuss the Wrox book Beginning HTML, XHTML, CSS, and JavaScript by Jon Duckett; ISBN: 978-0-470-54070-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning HTML, XHTML, CSS, and JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2011, 06:21 PM
Authorized User
 
Join Date: Feb 2011
Posts: 25
Thanks: 2
Thanked 1 Time in 1 Post
Default Using functions

I've got a problemswhere the answer has eluded me. everytime I deliberately type a user name with less than 6 characters, or intentionally type 2 different passwords, instead of getting a message saying that there was an error of some sort, and the focus going back to the form contols, the page just moves on.???

Here is the following code:

<?xml versionh="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Re-usable functions</title>

<script type="text/JavaScript">

function validateMinimumLength (control, length, errormessage) {
var error="";
document.getElementById(control.id).nextSibling.in nerHTML="";
if (control.value.length < length) {
error = errormessage;
document.getElementById(control.id).nextSibling.in nerHTML=errormessage;
document.getElementById(control.id).focus();
}
return error;
}

function validateConfirmPassword (password1, password2, errormessage) {
var error="";
document.getElementById(password1.id).nextSibling. innerHTML="";
if (password1.value != password2.value) {
error = errormessage;
document.getElementById(password1.id).nextSibling. innerHTML=errormessage;
document.getElementById(password1.id).focus();
}
return error;
}

function validate(form) {
var returnValue = "";

returnValue += validateConfirmPassword(form.txtPassword, form.txtPassword2,
'Your passwords did not match');

returnValue += validateMinimumLength(form.txtPassword, 6,
'Your password must be at least 6 characters long');

returnVlaue += validateMinimumLength(form.txtUserName, 6,
'Your username must be at least 6 characters long');

if (returnValue != "") {
return false;
}
return true;
}


</script>
</head>
<body>
<form name="frmRegister" method="post" action="register.aspx"
onsubmit="validate(this);">
<div>
<label for="txtUserName">Username:</label>
<input type="text" id="txtUserName" size="12"><span class="message"></span>
</div>
<div>
<label for="txtPassword">Password:</label>
<input type="password" id="txtPassword" size="12"><span class="message"></span>
</div>
<div>
<label for="txtPassword2">Confirm password:</label>
<input type="password" id="txtPassword2" size="12"><span class"message"></span>
</div>
<div>
<input type="submit" value="Log in">
</div>
</form>
</body>
</html>

Any help will again be grateful. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
C functions...??? ethantinder C# 2 April 25th, 2008 02:25 AM
Functions LTello BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 September 15th, 2006 11:15 AM
functions xelepi PHP How-To 1 March 10th, 2006 02:59 AM
Functions Meg Intro Programming 1 January 23rd, 2006 01:03 PM
Help with Functions megabytes C# 1 August 7th, 2003 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.