Issue with Onfocus Onblur in Password Field

Discussion in 'JavaScript' started by RedDem0n, Mar 23, 2010.

  1. #1
    So I have a username and password field with the onfocus onblur script.

    Basically what happens is

    1) When you first load the page - You will see Username and Password typed in already in the two form fields.

    2) When you click on the username, the username type disappears and you are able to type in your username. Same thing happens with the password.

    3) The problem is - On Firefox and Chrome both work out the way they are supposed too. However, on IE 8 - When you tab over to the password field, it gives me a JS error.

    "Could not get the type property. This command is not supported."

    Here is my code:
    <input class="search_textbox" value="Username" NAME="username" type="text" onfocus="clearText(this)" onblur="clearText(this)" />
    								<input class="search_textbox" type="text" name="password" value="Password" onFocus="if(this.value='Password'){this.value='';this.type='password';}">
    
    <input type="submit" value="Login" class="search_button"  />
    Code (markup):
    Any help would be appreciated.
     
    RedDem0n, Mar 23, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    IE does not like to change the inpute type dynamicaly. You have to replace the element with a new input element with type="password".
    Another solution where you wont need to change the input fields would be to place a div above the input fields an simply hide it when you focus the input fields.
     
    Nyu, Mar 23, 2010 IP
  3. RedDem0n

    RedDem0n Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nyu, thank you for your post. Would you mind coding the example you laid out? I would highly appreciate it.
     
    RedDem0n, Mar 23, 2010 IP
  4. RedDem0n

    RedDem0n Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Figured it out. Thanks.
     
    RedDem0n, Mar 24, 2010 IP