Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 12th, 2011, 06:21 PM
Authorized User
Points: 128, Level: 2
Points: 128, Level: 2 Points: 128, Level: 2 Points: 128, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:07 AM.


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