...

View Full Version : Simple Text Variable Error



shatterah
08-06-2008, 08:16 PM
I am attempting to actively add multiple lines of text to the bottom of the page based on if conditions. However I am having trouble with breaking each message into its own line, making the text red and bold, and having the text blink if possible. After reading some info online I thought I had the problem fixed, however instead I see the following in the browser:

<FONT COLOR="FF0000"><B>Password Must Contain Two Upper Case Letters.<br></B></FONT>

when I use this code snippet:
else { // adds warning text
var p3 = document.getElementsByTagName('upperCaseLetter')[0];
if (newPassword != 0 && p3 == null){ //only adds warning if a password is present and no warning message exists
var newPUpper = document.createElement("upperCaseLetter");
var txtUpper = "Password Must Contain Two Upper Case Letters." + "<br>";
txtUpper = txtUpper.bold().fontcolor("FF0000");
var newTUpper = document.createTextNode(txtUpper);
newPUpper.appendChild(newTUpper);
var theBody = document.getElementsByTagName('body')[0];
theBody.appendChild(newPUpper);
}//end of if statment

Any help is much appreciated!

shatterah
08-07-2008, 07:20 PM
I have updated my function to fix some of my previous problems. The idea is that when a user is actively typing in a password, it checks the complexity and updates which requirements are not meet. I have added the entire function responsible for this below. I did try using this:

var myUpperBreak=document.createElement("br");
theBody.appendChild(newPUpper);
theBody.appendChild(myUpperBreak);

and it worked however, each time a message would reappear, it would lower on the page. Here is my entire function:

function testPassword (newPassword) {

if (newPassword.match(/([a-z].*[a-z])/)) // checks for two lower case letters
{
var p2 = document.getElementById('lowerCaseLetter');
if (p2 != null){ //checks to see if there already exists warning text and removes it
p2.parentNode.removeChild(p2);
}//end of if statement
}//end of if statement
else { // adds warning text
var p2 = document.getElementById('lowerCaseLetter');
if (newPassword != 0 && !p2){ //only adds warning if a password is present and no warning message exists
var newPLower = document.createElement('span');
newPLower.id = 'lowerCaseLetter';
var txtLower = 'Password Must Contain Two Lower Case Letters.';
newPLower.style.fontWeight = 'bold';
newPLower.style.color = 'blue';
newPLower.appendChild(document.createTextNode(txtL ower));
document.body.appendChild(newPLower);
}//end of if statment
else {//removes warning message if password is not entered and warning message exsists
if (newPassword == 0 && p2 != null){
p2.parentNode.removeChild(p2);
}//end of if statement
}//end of else statement
}// end of else statement

if (newPassword.match(/([A-Z].*[A-Z])/)) // checks for two upper case letters
{
var p3 = document.getElementById('upperCaseLetter');
if (p3 != null){ //checks to see if there already exists warning text and removes it
p3.parentNode.removeChild(p3);
}//end of if statement
}//end of if statement
else { // adds warning text
var p3 = document.getElementById('upperCaseLetter');
if (newPassword != 0 && !p3){ //only adds warning if a password is present and no warning message exists
var newPUpper = document.createElement('span');
newPUpper.id = 'upperCaseLetter';
var txtUpper = "Password Must Contain Two Upper Case Letters.";
newPUpper.style.fontWeight = 'bold';
newPUpper.style.color = 'red';
newPUpper.appendChild(document.createTextNode(txtU pper));
document.body.appendChild(newPUpper);
}//end of if statment
else {//removes warning message if password is not entered and warning message exsists
if (newPassword == 0 && p3 != null){
p3.parentNode.removeChild(p3);
}//end of if statement
}//end of else statement
}// end of else statement

}//end of function testPassword



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum