<?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>Monday By Noon &#187; input</title>
	<atom:link href="http://mondaybynoon.com/tag/input/feed/" rel="self" type="application/rss+xml" />
	<link>http://mondaybynoon.com</link>
	<description>A resource for Web designers and developers to read about and discuss their craft.</description>
	<lastBuildDate>Wed, 08 Feb 2012 13:49:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>&#8226; Creating Named Elements in IE via JavaScript. Impossible?</title>
		<link>http://mondaybynoon.com/feeder/?FeederAction=clicked&#038;feed=Posts+%28RSS2%29&#038;seed=http%3A%2F%2Fmondaybynoon.com%2F20070924%2Fcreating-named-elements-in-ie-via-javascript-impossible%2F&#038;seed_title=%26%238226%3B+Creating+Named+Elements+in+IE+via+JavaScript.+Impossible%3F</link>
		<comments>http://mondaybynoon.com/20070924/creating-named-elements-in-ie-via-javascript-impossible/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 12:40:14 +0000</pubDate>
		<dc:creator>Jonathan Christopher</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[Internet-Explorer]]></category>
		<category><![CDATA[name]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://mondaybynoon.com/2007/09/24/creating-named-elements-in-ie-via-javascript-impossible/</guid>
		<description><![CDATA[I was having a bit of an issue trying to create a new element via the DOM and provide it with a name. As it turns out, Internet Explorer doesn&#8217;t allow this to happen, but I was able to find an alternative solution that has worked out quite well.<br /><p><a href='http://rss.buysellads.com/click.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=100&c=1026863459' target='_blank' rel='nofollow'>
				<img src='http://rss.buysellads.com/img.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=100&c=1026863459' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/2ee344414ac81fbb0f9de6ab08e9831e/zone/1269068' target='_blank'>Advertise here with BSA</a></p>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s almost humorous to me that I still to this day find new quirks and bugs within Internet Explorer. I try to keep everything in mind as I work on a project, in an effort to be one step ahead when it comes to testing in <abbr title="Internet Explorer">IE</abbr>, but it&#8217;s not always easy.</p>
<p>Last week, a project was to enhance a <code>form</code> on a client website by integrating the addition of new fields via JavaScript. The basic idea is this; there is a section in the <code>form</code> where a number of file <code>inputs</code> would need to be duplicated based on the need of the reader filling out the form. The number of file inputs could range from one to an unlimited number, which, come to think of it, I need to revisit. But I digress.</p>
<p>As I was working with the <code>form</code>, I began to notice that it wasn&#8217;t working improperly in Internet Explorer 6 or Internet Explorer 7. The script kept track of how many <code>inputs</code> had been added via a simple counter, and provided a <code>name</code> attribute reflecting that number using an established naming convention. It was the basis for allowing multiple file uploads.</p>
<p>I tested again using Firefox and everything appeared to be fine. My next step was to check out what was going on with the <acronym title="Document Object Model">DOM</acronym> in IE.</p>
<h3>Viewing Generated Source in <abbr title="Internet Explorer">IE</abbr></h3>
<p>As we all know, there aren&#8217;t too many developer resources for working with Internet Explorer. The <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=E59C3964-672D-4511-BB3E-2D5E1DB91038&amp;displaylang=en">Internet Explorer Developer Toolbar</a> is about the only tool that really helps you to diagnose any troubles you may be having. It has come in handy for me from time to time, but personally I think it&#8217;s a bit awkward to use and generally end up resorting to a quick <code>border:1px solid #f00;</code> to help me diagnose any troubles I may be having with <abbr title="Cascading Style Sheets">CSS</abbr> in IE.</p>
<p>In this case nothing like that could have helped, so I resorted to the Developer Toolbar and realized that <em>none of the created elements had a <code>name</code></em> in Internet Explorer 6 or 7. Everything was working fine in other browsers, so I wasn&#8217;t sure exactly what was going on. After a bit of searching, I found that IE simply does not support the application of a <code>name</code> attribute to an element created via DOM scripting. Ridiculous.</p>
<p>As an aside, I also came across a quick tip on replicating the View Generated Source functionality of the <a href="http://chrispederick.com/work/web-developer/">Web Developer Toolbar for Firefox</a>, a feature I find myself using quite a bit. You can explore the generated DOM using the Developer Toolbar in Internet Explorer, but the following snippet will display the generated source in plain text, just paste it in the location bar.</p>
<pre><code>javascript:'&lt;xmp&gt;' + window.document.body.outerHTML+ '&lt;/xmp&gt;'</code></pre>
<p>Continuing: A bit more research narrowed the scope of this &#8216;issue&#8217;. It turns out the IE more specifically <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/name_2.asp">does not allow</a> the <code>name</code> of an element to be changed after it has been created. Bummer. What do do about it?</p>
<p>Thankfully, the Internet is full of extremely intelligent people. Most of the time, other people have had the same exact problem you&#8217;re having, they have written about it, and also (hopefully) provided a solution to help you out. This was one of those cases. In the article <a href="http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/">Setting the &#8220;name&#8221; attribute in Internet Explorer</a>, a fix for this problem is offered in the following function:</p>
<pre><code>function createNamedElement(type, name) {
  var element = null;
  // Try the IE way; this fails on standards-compliant browsers
  try {
    element = document.createElement('&lt;'+type+' name="'+name+'"&gt;');
  } catch (e) {
  }
  if (!element || element.nodeName != type.toUpperCase()) {
    // Non-IE browser; use canonical method to create named element
    element = document.createElement(type);
    element.name = name;
  }
  return element;
}</code></pre>
<p>Essentially, the function checks to see whether or not the reader is using Internet Explorer, and implements the element accordingly. I also happened to find another solution that uses the conditional comment method:</p>
<pre><code>/*@cc_on @if (@_jscript)
var newNode = document.createElement('&lt;input name="'+elementName+'"&gt;');
@else */
var newNode = document.createElement('input');
newNode.name = elementName;
/* @end @*/</code></pre>
<p>Many developers have their own opinions about using conditional comments both in <abbr title="(eXtensible) HyperText Markup Language">(X)HTML</abbr> as well as JavaScript, so it was nice to find examples both with and without. Which would you prefer?</p>
<p>Hopefully, if you haven&#8217;t come across or read about this bug before, you&#8217;ll remember it when it comes to your next Web app as you ad progressive enhancement in dynamic addition of elements requiring a <code>name</code>.</p>
<p><strong>References</strong></p>
<ul class="references">
<li><a href="http://ericappel.net/blog/ViewHTMLSourceGeneratedByAJAX.aspx">View HTML Source Generated by AJAX</a></li>
<li><a href="http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/">Setting the “name” attribute in Internet Explorer</a></li>
</ul>
<br /><p><a href='http://rss.buysellads.com/click.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=100&c=1766214181' target='_blank' rel='nofollow'>
				<img src='http://rss.buysellads.com/img.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=100&c=1766214181' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/2ee344414ac81fbb0f9de6ab08e9831e/zone/1269068' target='_blank'>Advertise here with BSA</a></p>]]></content:encoded>
			<wfw:commentRss>http://mondaybynoon.com/20070924/creating-named-elements-in-ie-via-javascript-impossible/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Database Caching 1/48 queries in 0.118 seconds using apc
Object Caching 474/530 objects using apc

Served from: www.mondaybynoon.com @ 2012-02-10 19:27:55 -->
