javascript - change input type from text to password or vice versa
i guess first you tried this code change type. however code doesn't work on ie 6.

document.getElementById(id).type = 'text';

here's a tiny function that i wrote to solve problem. first we create an input box, then we get the value of old input and set it for new one, finally remove old box and add new.



<script>
function passText(id)
{
    el = document.getElementById(id);

    var newinput = document.createElement('input');
    newinput.setAttribute('id', id);
    newinput.setAttribute('name', id);
    newinput.setAttribute('value', el.value);
    (el.type == 'password') ? newinput.setAttribute('type', 'text') : newinput.setAttribute('type', 'password');

    el.parentNode.insertBefore(newinput, el.nextSibling);
    el.parentNode.removeChild(el);
}
</script>

<input type="password" name="password" id="password" value="" />

<a href="#" onclick="passText('password')">change</a>



Ad Soyad:
E-posta:
Web site:
şuralara da bakın derim

Burak İlem

Ali Yılmaz