Changing input type in IE?

Discussion in 'Javascript' started by cjl, Oct 18, 2005.

  1. cjl

    cjl Guest

    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
     
    cjl, Oct 18, 2005
    #1
    1. Advertisements

  2. 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 пиÑал(а):
     
    Gomolyako Eduard, Oct 18, 2005
    #2
    1. Advertisements

  3. 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);
     
    Martin Honnen, Oct 18, 2005
    #3
  4. cjl

    web.dev Guest

    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.
     
    web.dev, Oct 18, 2005
    #4
  5. cjl

    cjl Guest

    Hey all:

    Thank you to all who replied.
    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
     
    cjl, Oct 18, 2005
    #5
  6. Cross-browser scripting is inherently complicated. Not supporting IE
    doesn't strike me as a viable option.
     
    Christopher Benson-Manica, Oct 18, 2005
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.