2

i have the following simple script

<input class="input"  type="text" name="password" style="color: #797272;" 
       value= "<?php if ($_POST[password] != '') {echo '';}
         else {echo 'Ծածկաբառ';}?>"   
        onclick="if (this.value === this.defaultValue) {
                   this.value='';
                   this.style.color='black';
                   this.type='password';
                   }" 

      />

it works fine, but in IE7 it doesn't change the input type.

this.type='password'; doesn't work

could you help me? thanks

update

and what can i do, if i want to show default value in thet input?

5 Answers 5

2

Sadly IE doesn't allow input tag to change to or from password type. Very annoying. 'They' say it is for security reasons, but every other browser allows it...

Sign up to request clarification or add additional context in comments.

Comments

2

You can't change the type of inputs with JS in Internet Explorer, and the approach you are taking has other implications (such as accessibility problems).

Taking a different approach and having a positioned label element avoids the problem of changing the field and reduces the accessibility issues greatly. I wrote an example: http://dorward.me.uk/tmp/label-work/example.html

1 Comment

Oh joy, a bug. (There's a reason why it lives in /tmp/ at the moment). The principle is sound though.
1

If it is in IE 6, it seems that you cannot change the type... you can however replace the entire element:

http://bytes.com/topic/javascript/answers/705445-dynamically-change-input-type-text-password

Comments

1

You simply can't do this in IE, it doesn't allow you to change the type once it's been added to the DOM. To do this, you have to replace the input completely.

From the documentation:

As of Microsoft Internet Explorer 5, the type property is read/write-once, but only when an input element is created with the createElement method and before it is added to the document.

Comments

0

the only one solution i found, it works fine

function change() 
    {
        var input=document.getElementById('some');
        var input2= input.cloneNode(false);
        input2.type='password';
        input.parentNode.replaceChild(input2,input);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.