<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>arjansnaterse.nl &#187; Internet Explorer</title>
	<atom:link href="http://arjansnaterse.nl/tag/internet-explorer/feed" rel="self" type="application/rss+xml" />
	<link>http://arjansnaterse.nl</link>
	<description></description>
	<lastBuildDate>Wed, 02 Dec 2009 07:48:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Changing type attribute in IE</title>
		<link>http://arjansnaterse.nl/changing-type-attribute-in-ie</link>
		<comments>http://arjansnaterse.nl/changing-type-attribute-in-ie#comments</comments>
		<pubDate>Tue, 26 Aug 2008 09:14:28 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://arjansnaterse.nl/?p=43</guid>
		<description><![CDATA[I never had noticed this before, but a little while ago I found out that changing the type attribute on an input box doesn&#8217;t work in Internet Explorer. Not in IE6 and even not in IE7. I tried element.type="text"; and element.setAttribute("type", "text"); but both methods didn&#8217;t work. Strange, because these methods won&#8217;t give any problems [...]<p><a href="http://arjansnaterse.nl/changing-type-attribute-in-ie">Changing type attribute in IE</a> is a post from: <a href="http://arjansnaterse.nl">arjansnaterse.nl</a></p>
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Farjansnaterse.nl%2Fchanging-type-attribute-in-ie"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Farjansnaterse.nl%2Fchanging-type-attribute-in-ie&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Changing type attribute in IE" alt=" Changing type attribute in IE" /><br />
			</a>
		</div>
<p>I never had noticed this before, but a little while ago I found out that changing the <code>type </code>attribute on an input box doesn&#8217;t work in Internet Explorer. Not in IE6 and even not in IE7.</p>
<p>I tried <code>element.type="text";</code> and <code>element.setAttribute("type", "text");</code> but both methods didn&#8217;t work. Strange, because these methods won&#8217;t give any problems for setting any other attribute. Sigh.. that Microsoft again&#8230;</p>
<p>Fortunately there is a solution. It&#8217;s a little dirty and extensive, but hey, it works! The basic idea is that you have to create an new input element and replace it with the old one. The paradox here is that you can set the type attribute for newly created objects with no problems, but editing an existing one give problems. Why? I don&#8217;t know. But I&#8217;m happy that there&#8217;s a solution :-)</p>
<p>Anyway, here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> changeInputType<span style="color: #009900;">&#40;</span>oldObject<span style="color: #339933;">,</span> oType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> newObject <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	newObject.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> oType<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// 'Copy' old types to new element</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oldObject.<span style="color: #660066;">size</span><span style="color: #009900;">&#41;</span>
		newObject.<span style="color: #660066;">size</span> <span style="color: #339933;">=</span> oldObject.<span style="color: #660066;">size</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oldObject.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>
		newObject.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> oldObject.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oldObject.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span>
		newObject.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> oldObject.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oldObject.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span>
		newObject.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> oldObject.<span style="color: #660066;">id</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oldObject.<span style="color: #660066;">className</span><span style="color: #009900;">&#41;</span>
		newObject.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> oldObject.<span style="color: #660066;">className</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// replace old object with new one</span>
	oldObject.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">replaceChild</span><span style="color: #009900;">&#40;</span>newObject<span style="color: #339933;">,</span>oldObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> newObject<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><a href="http://arjansnaterse.nl/changing-type-attribute-in-ie">Changing type attribute in IE</a> is a post from: <a href="http://arjansnaterse.nl">arjansnaterse.nl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://arjansnaterse.nl/changing-type-attribute-in-ie/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
