Web Analytics Made Easy -
StatCounter Field onClick - CodingForum

Announcement

Collapse
No announcement yet.

Field onClick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Field onClick

    I'm currently working on a log-in form. What I would like to do is have the Password text field have the plain text 'Password' in it. When the user clicks on the password field, I want the text to clear and the field type to be changed to a password to mask the characters.

    I have achieved this using the following code:
    Code:
    <input name="PassWord" onFocus="this.type='password'; this.value=''" value="Password" />
    Everything goes fine - upon focus the field clears itself and changes its type to password, however, after doing so, it loses focus on the field, meaning you have to click in the field again to enter your password. Can anyone advise me as to how to get it to perform the aforementioned actions and keep focus on the field?

  • #2
    Well without testing I'm guessing you're going to have a problem because focusing on it again would change it to a password field.

    I guess you could try something like this:

    <input name="PassWord" onclick="this.type='password'; this.value=''; this.focus()" value="Password" />

    Edit: Tested the above and this works in Firefox but not IE (not tested in other browsers); the type property should actually be read-only so I have no idea why Firefox allows you to change it!
    Last edited by mark87; Oct 10, 2006, 07:04 PM.
    markaylward.co.uk

    Comment


    • #3
      Originally posted by mark87 View Post
      Well without testing I'm guessing you're going to have a problem because focusing on it again would change it to a password field.

      I guess you could try something like this:

      <input name="PassWord" onclick="this.type='password'; this.value=''; this.focus()" value="Password" />

      Edit: Tested the above and this works in Firefox but not IE (not tested in other browsers); the type property should actually be read-only so I have no idea why Firefox allows you to change it!
      Thanks for the quick reply. It isn't a major issue, but one I'd like to have solved. I'm pretty sure most of the users on the site are using Firefox anyway.

      Thanks again!

      Comment

      Working...
      X