PDA

View Full Version : Form help



Shwaza
Jul 22nd, 2005, 06:09 PM
Hi, I have a function that is called onblur of a form field:

function p_check(){
password=document.register.password.value;
if(password != ''){
document.getElementById('p_div').innerHTML='<input type="password" value="' + password + '" name="password" /><img src="images/green_check.gif" />';
}
else{
if(password == ''){
document.getElementById('p_div').innerHTML='<input type="password" value="" name="password" />';
}
}
}

What it should do, is if the password field has something in it after the person has gone away from that field, is change the div "p_div"'s inner html to be the same as before, except with a green check mark image. This part all works fine, however if I enter a password, leave the field, come back to it, empty the field and move away from the field again, the green check mark stays.

Can someone help?

Thanks!

Mr J
Jul 22nd, 2005, 07:19 PM
You need to create a blank image to replace your green_check image or you could use css visibility to hide and show the image


function p_check(){
password=document.register.password.value;
if(password != ''){
document.getElementById('p_div').innerHTML='<input type="password" value="' + password + '" name="password" /><img src="images/green_check.gif" />';
}
else{
if(password == ''){
document.getElementById('p_div').innerHTML='<input type="password" value="" name="password" /><img src="images/blank.gif" />';
}
}
}

Shwaza
Jul 22nd, 2005, 07:59 PM
Ok, I tried this:

function p_check(){
password=document.register.password.value;
if(password != ''){
document.getElementById('p_div').innerHTML='<input type="password" value="' + password + '" name="password" /><img src="images/green_check.gif" alt="good" id="p_icon" />';
}
else{
if(password == ''){
document.getElementById('p_div').innerHTML='<input type="password" value="" name="password" /><img src="images/red_x.gif" alt="bad" id="p_icon" />';
}
}
}

But it still dosn't change :S BTW, here's the actual file: http://www.kingdomsofbattle.com/register.php

Mr J
Jul 22nd, 2005, 10:36 PM
That is not exactly the code thats in your page, this is


function p_check(){
password=document.register.password.value;
if(password != ''){
//document.getElementById('p_div').innerHTML='<input type="password" value="' + password + '" name="password" /><img src="images/green_check.gif" alt="good" id="p_icon" />';
document.register.p_icon.src='images/green_check.gif';
}
else{
if(password == ''){
//document.getElementById('p_div').innerHTML='<input type="password" value="" name="password" /><img src="images/red_x.gif" alt="bad" id="p_icon" />';
document.register.p_icon.src='images/red_x.gif';
}
}
}

All instances of document.register.p_icon.src= should be

document.p_icon.src=

and all instances of document.register.u_icon.src= should be

document.u_icon.src=

You do not include the form name when referencing the images.

So you should have something like



function p_check(){

password=document.register.password.value;
if(password != ''){
document.p_icon.src='images/green_check.gif';
}
else{
document.p_icon.src='images/red_x.gif';
}

}