Skip to main content

Bug Tracker

Side navigation

#1536 closed bug (fixed)

Opened August 26, 2007 01:58PM UTC

Closed October 19, 2009 01:38AM UTC

Last modified March 14, 2012 03:17AM UTC

Jquery cant change input type in IE

Reported by: icereaper Owned by:
Priority: major Milestone: 1.2
Component: core Version: 1.1.4
Keywords: Cc:
Blocked by: Blocking:
Description

Situation:

<input type="text" class="testClass" value="Password"/>

Exspected Result:

<input type="password" class="testClass" value=""/>

For all browsers:

$(this).attr('type','password');

$(this).val('');

IE gives JS Error cause it cant change the type.

Attachments (0)
Change History (12)

Changed August 30, 2007 01:39AM UTC by arrix comment:1

Microsoft enforces read/write-once-rule for the type-attribute of <input>-elements.

See http://docs.jquery.com/Core#.24.28_html_.29

Changed September 04, 2007 04:17AM UTC by john comment:2

resolution: → fixed
status: newclosed

Attempting to do this now throws an exception in all browsers. Fixed in SVN rev [3096].

Changed September 11, 2007 04:29PM UTC by abcdmitry comment:3

resolution: fixed
status: closedreopened

There is a solution for this kind of problem described at

http://www.dynamicsitesolutions.com/javascript/dynamically-changing-input-type/

It creates a clone of element with same attributes except for type. That might help because changing the type of input element via jQuery is a really sweet feature.

Changed September 15, 2007 01:23PM UTC by john comment:4

resolution: → fixed
status: reopenedclosed

Unfortunately, this particular hack is not feasible within jQuery (you also have to worry about issues like copying styles and events of the object) - since old jQuery matched sets may reference old versions of the input element, for example:

{{{

var fields = $("input")

$("input:first").attr("type", "hidden");

fields[0].type == "text"

}}

Until there's a way around that, we're going to have to be content with the current solution.

Changed September 17, 2007 02:17PM UTC by jespern comment:5

Not very smart making this throw an exception in all browsers. I was just about to file a bug on this.

It's possible outside IE, and Applesearch uses it to change the input type in Safari to 'search'. Guess I'll have to throw out the original element and replace it with a new one. Please just keep it in mind before making such a change.

Changed March 12, 2009 10:10AM UTC by ArbuZz comment:6

resolution: fixed
status: closedreopened

In my WordPress plugin I've used the following method of changing the type on the fly (cross-browser), maybe it may help someone or incorporated into the jQuery itself. This example alters type="password" to type="text":

var e = $(':password')[0];

e.replaceWith($(e.wrap('<label></label>').parent('label').html().replace(/type=\\"?password\\"?/, 'type="text"')));

Changed March 12, 2009 11:42PM UTC by dmethvin comment:7

resolution: → fixed
status: reopenedclosed

Changed March 13, 2009 06:50AM UTC by ArbuZz comment:8

Sorry, doesn't seem to work as it should. For some reason jQuery fails to construct proper input element. Had to rewrite constructor in pure javascript.

Changed July 27, 2009 07:45AM UTC by btech_saurabh comment:9

resolution: fixed
status: closedreopened

Not a good way of doing this.

Changed July 27, 2009 07:51AM UTC by btech_saurabh comment:10

Hi

I have an input type of text.

<input id="iPassword" value="Password" type="text"/>

in jQuery I want to change the type="password" when someone focus on it.

I tried this

$('#iPassword').focus(function(){

$(this).attr("type","password");

});

but it doesn't work.

any Ideas??

Changed October 19, 2009 01:38AM UTC by dmethvin comment:11

resolution: → fixed
status: reopenedclosed

Please do not reopen tickets to ask for programming help, just ask the question in the forums.

This issue is fixed as well as it can be considering IE's only-set-it-once rule for the

type
attribute of
input
elements.

Changed March 30, 2011 07:32PM UTC by rwaldron comment:12

#7410 is a duplicate of this ticket.