Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13893 > unrolled thread

Change type of <input>

Started by"Tom de Neef" <tdeneef@qolor.nl>
First post2012-05-13 11:38 +0200
Last post2012-05-13 14:30 +0200
Articles 4 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Change type of <input> "Tom de Neef" <tdeneef@qolor.nl> - 2012-05-13 11:38 +0200
    Re: Change type of <input> Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2012-05-13 12:44 +0200
    Re: Change type of <input> "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-05-13 13:55 +0300
      Re: Change type of <input> "Tom de Neef" <tdeneef@qolor.nl> - 2012-05-13 14:30 +0200

#13893 — Change type of <input>

From"Tom de Neef" <tdeneef@qolor.nl>
Date2012-05-13 11:38 +0200
SubjectChange type of <input>
Message-ID<4faf80fe$0$6958$e4fe514c@news2.news.xs4all.nl>
I try to change the type of an <input> element from 'text' to 'password'.
No problem in FF an Chrome but IE8 will not allow it. In below code it stops 
in the function saying (translated from Dutch) "cannot retrieve attribute; 
operation not supported".
Is that the end of the story, i.e. must I accept that I can not change from 
'text' to 'password'? Or is there an alternative approach?
TIA
Tom

{code}
<html>
<head><title>Test</title>
<script type="text/javascript">
  function test() {
  var el = document.getElementById('pw');
  el.type = "password"
  }
</script>
</head>

<body>
<form>
  <input id="pw" type="text" value="some value">
</form>

<span onclick="test()">CHECK PASSWORD</span>
</body>

</html>
{code} 

[toc] | [next] | [standalone]


#13897

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2012-05-13 12:44 +0200
Message-ID<joo3b3$8b7$1@news.albasani.net>
In reply to#13893
Tom de Neef schrieb:
> I try to change the type of an <input> element from 'text' to 'password'.
> No problem in FF an Chrome but IE8 will not allow it.
> Is that the end of the story, i.e. must I accept that I can not change from 
> 'text' to 'password'? Or is there an alternative approach?

You could create a new <input> element and set its type to 'password' -- 
IE allows this when no type has been set before. Then set all other 
attributes you need and replace the original element with the new one.

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#13898

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2012-05-13 13:55 +0300
Message-ID<joo3vd$a6b$1@dont-email.me>
In reply to#13893
2012-05-13 12:38, Tom de Neef wrote:

> I try to change the type of an<input>  element from 'text' to 'password'.
> No problem in FF an Chrome but IE8 will not allow it.

Indeed. See the comments at
http://stackoverflow.com/questions/9419780/javascript-show-hide-password
which also includes notes on an approach based on changing the 
visibility of a password field. That is, instead of changing the type of 
an <input> element, include both <input type=password> and <input 
type=text>, and just control the visibility.

Or you could dynamically create a password field, add it to the 
document, and remove the text field.

> Or is there an alternative approach?

There's always an alternative approach. But it depends on the problem 
which approach is best. You haven't said anything about the real 
problem, just described code that presumably was meant to address a 
problem. Why on &Planet; would you want to change a text input field to 
a password input field? They're equivalent except for the obscured input 
echo in a password field and some browsers' policy of treating password 
fields differently when they store and reuse user input.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#13899

From"Tom de Neef" <tdeneef@qolor.nl>
Date2012-05-13 14:30 +0200
Message-ID<4fafa970$0$6937$e4fe514c@news2.news.xs4all.nl>
In reply to#13898
"Jukka K. Korpela" <jkorpela@cs.tut.fi> schreef in bericht 
news:joo3vd$a6b$1@dont-email.me...
> 2012-05-13 12:38, Tom de Neef wrote:
>
>> I try to change the type of an<input>  element from 'text' to 'password'.
>> No problem in FF an Chrome but IE8 will not allow it.
>
> Indeed. See the comments at
> http://stackoverflow.com/questions/9419780/javascript-show-hide-password
> which also includes notes on an approach based on changing the visibility 
> of a password field. That is, instead of changing the type of an <input> 
> element, include both <input type=password> and <input type=text>, and 
> just control the visibility.
>
> Or you could dynamically create a password field, add it to the document, 
> and remove the text field.
>
>> Or is there an alternative approach?
>
> There's always an alternative approach. But it depends on the problem 
> which approach is best. You haven't said anything about the real problem, 
> just described code that presumably was meant to address a problem. Why on 
> &Planet; would you want to change a text input field to a password input 
> field? They're equivalent except for the obscured input echo in a password 
> field and some browsers' policy of treating password fields differently 
> when they store and reuse user input.
>

This concerns a traditional windows application with a shell around it that 
is able to render the app's UI in html or xml. A server sits between it and 
the client. The app had a form with a button to show/hide password 
characters. The shell has translated that into a html page. It detects that 
the result of the button's click event is a change in type of the input 
control of the underlying app. It sends this modification back to the client 
as an xml message saying: change attribute 'type' of element.id to 
'password'.
For this particular modification it will have to say something along the 
lines of: replace element.id by a copy with type=password.

Tom 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web