Setting visible default value for password form field

Hi,

I have a password field like this:

<input name=“site_assword” type=“password” class=loginform value=“password” size=“10” onfocus=“this.value=‘’;” onblur=“if (this.value==‘’) {this.value=‘password’;}”>

It shows a default value which dissapears when the user clicks on the password field. However, because the input field type is set to ‘password’, whatever I set as the default value is masked by *

Is there any way around this to make normal text appear but still have the input box masked when they start to type the password?

Thanks,
the_crum

You could try something like this:


<input name="site_password1" type="input" class="loginform" value="password" size="10" onfocus="this.style.display = 'none'; document.getElementsByName('site_password2')[0].style.display = ''; document.getElementsByName('site_password2')[0].focus();" />

<input name="site_password2" type="password" class="loginform" value="" size="10" style="display: none;" onblur="if (this.value == '') { this.style.display = 'none'; document.getElementsByName('site_password1')[0].style.display = '';}" />

What this does is displays the empty password element when you click on the input element. If you then unclick the password element leaving it blank the original input element will appear with a value of ‘password’.

Note: I used getElementsByName()[0] instead of getElementsById (which would be perfectly valid if an id was set) just because i head it was better that way round, don’t quite know if this is true, any ideas?

Good Luck,
Ajc

That worked great, cheers!

I have another related problem.

In the form where I use the field above there is also a username field like this:

<input name=“username” type=“text” class=loginform value=“username” size=“10” onfocus=“this.value=‘’;” onblur=“if (this.value==‘’) {this.value=‘username’;}”>

I also have a login button like this:

<a href=“javascript:go_login();”>login</a>

When i click the login button it calls a javascript but for a few seconds, as the next page loads, the value of the username field reverts back to “username” instead of keeping the value that the user has entered.

Any idea how I could stop this happening as it could confuse users?

Thanks

Would you mind showing us a bit of code so we can get a good look at the problem?
From what you have said i can only guess that there is something in the go_login() function that is causing this.

Good Luck,
Ajc

It’s ok, I got it fixed now. Your right, it was something in the go_login function.

Thanks