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. Advertising

  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 пиÑал(а):

    > 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
     
    Gomolyako Eduard, Oct 18, 2005
    #2
    1. Advertising

  3. cjl wrote:

    > 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);


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 18, 2005
    #3
  4. cjl

    web.dev Guest

    Martin Honnen wrote:
    > cjl wrote:
    >
    > > 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);


    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.

    > 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
     
    cjl, Oct 18, 2005
    #5
  6. cjl <> wrote:

    > 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.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 18, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gladriel

    changing input type file

    Gladriel, May 17, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    175
    Teemu Keiski
    May 17, 2004
  2. Boyd Reilly

    Changing Input Type, length and value

    Boyd Reilly, Jan 11, 2004, in forum: Javascript
    Replies:
    4
    Views:
    144
    Jim Ley
    Jan 13, 2004
  3. Ron Brennan
    Replies:
    5
    Views:
    316
    Dr John Stockton
    May 14, 2004
  4. Michael Winter

    changing input.type error with IE

    Michael Winter, Oct 14, 2004, in forum: Javascript
    Replies:
    2
    Views:
    103
    vastaso
    Oct 14, 2004
  5. Tarkeshwar
    Replies:
    2
    Views:
    195
Loading...

Share This Page