Hey people,

Cheers for checkin this, its a pretty simple concept but theres a bug which is annoying me, any feedback is appreciated.

Ive got a script which is used to assign username and password form inputs default values of "Username (E-mail)" and "Password"

The problem is, the script changes the input type of the password input from password to text to make the "password" value legible but for some reason theres a slight delay between assigning the value and changing the input type, this causes "********" to be displayed briefly.

var f = document.getElementById('LoginForm');

if (f && f.customer_username) 
{
	var siteusertext = f.customer_username;

	siteusertext.value = 'Username (E-Mail)';
	// Clear the text box when you click in it
	var f = function() 
	{
		if(siteusertext.value == 'Username (E-Mail)')
		{ 
			siteusertext.value = ''; 
		}
	}
	
	var b = function() 
	{ 		
		if(siteusertext.value == '')
		{
			siteusertext.value = 'Username (E-Mail)';
		}  
	}
	
	siteusertext.onfocus = f;
	siteusertext.onblur = b;
}

var pf = document.getElementById('LoginForm'); 

if (pf && pf.customer_password) 
{
	var sitepasstext = pf.customer_password;

	sitepasstext.type = 'text';
	sitepasstext.value = 'Password'; 

	// Clear the input when you click in it
	var pf = function() 
	{
		if(sitepasstext.type == 'text')
		{
			sitepasstext.type = 'password';
			sitepasstext.value = ''; 
		}
	}
	var pb = function() 
	{
		if(sitepasstext.value == '')
		{ 
			sitepasstext.type = 'text';
			sitepasstext.value = 'Password'; 
		}
	}
	
	sitepasstext.onfocus = pf;
	sitepasstext.onblur = pb;
}

I can't imagine changing the type property to be that slow but what if you remove the value first?

// Clear the input when you click in it
	var pf = function() 
	{
		if(sitepasstext.type == 'text')
		{
			
			sitepasstext.value = ''; 
			sitepasstext.type = 'password';
		}
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.