Changing input type in IE?

C

cjl

Hey all:

This code:

if (stealth)
{
document.searchme.query.type = 'password';
}
else
{
document.searchme.query.type = 'text';
}

works in FF but not in IE 6. It fails with "Error: Could not get the
type property. This command is not supported."

A previous post mentioned that in IE type is 'read only'.

Are there any work around for changing input type dynamically in IE?

Thanks in advance,
-CJL
 
G

Gomolyako Eduard

You can dynamically insert new "input" element with correct type before
"query", after that remove "query" element and rename added "input"
element to "query".

Or you can define to "input" elements: one with text type, other with
password type and dynamically disable incorrect element. Disabled
inputs don't posts to server.

Best, Ed.

cjl пиÑал(а):
 
M

Martin Honnen

cjl said:
Are there any work around for changing input type dynamically in IE?

You can create a new input with
var input = document.createElement('input')
and set the type on that, then swap the elements with e.g.
oldInput.parentNode.replaceChild(input, oldInput);
 
W

web.dev

Martin said:
You can create a new input with
var input = document.createElement('input')
and set the type on that, then swap the elements with e.g.
oldInput.parentNode.replaceChild(input, oldInput);

cjl,

In addition to what Martin wrote, after you create the "input" element,
you can only set the type once (in IE). If you try to set the type
again, then you'll get the error message again.
 
C

cjl

Hey all:

Thank you to all who replied.
Martin Honnen wrote:
In addition to what Martin wrote, after you create the "input" element,
you can only set the type once (in IE). If you try to set the type
again, then you'll get the error message again.

All of this makes me not want to support IE, which up until this point
I have been making compromises to do.

My users need to be able to swap between stealth mode and normal mode,
so I guess I could have two input text boxes, and show or hide them
dynamically based on what mode they choose, but then I would have to
copy the text input from one to another to make it seamless.

This is getting complicated.

Thanks again,
CJL
 
C

Christopher Benson-Manica

cjl said:
All of this makes me not want to support IE, which up until this point
I have been making compromises to do.
This is getting complicated.

Cross-browser scripting is inherently complicated. Not supporting IE
doesn't strike me as a viable option.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top