<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Some Insight Into The Document Object Model: How Forms Are Stored By JavaScript</title>
	<atom:link href="http://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/</link>
	<description>ASP.NET, PHP, XML, JavaScript, Web geekery, Entrepreneurship</description>
	<lastBuildDate>Fri, 18 May 2012 10:23:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: matt</title>
		<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/#comment-135</link>
		<dc:creator>matt</dc:creator>
		<pubDate>Sat, 01 Aug 2009 02:09:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.dougv.com/blog/?p=346#comment-135</guid>
		<description>Excellent article that really sheds light on the subject, thanks. Also, a big thanks to Kiall for his addendum, of which I would probably still be lost.</description>
		<content:encoded><![CDATA[<p>Excellent article that really sheds light on the subject, thanks. Also, a big thanks to Kiall for his addendum, of which I would probably still be lost.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Vanderweide</title>
		<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/#comment-134</link>
		<dc:creator>Doug Vanderweide</dc:creator>
		<pubDate>Mon, 05 Jan 2009 22:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.dougv.com/blog/?p=346#comment-134</guid>
		<description>What Kiall describes is the difference between accessing a namespace member and calling a class method. It&#039;s an example of why you should never use reserved words as a variable name, too.

In the case of his code example, &lt;code&gt;document.forms[0].submit&lt;/code&gt; basically says, &quot;in the current document, find the first form on the page, and give me the element in that form named &quot;submit.&quot; &lt;code&gt;document.forms[0].submit()&lt;/code&gt; says, &quot;in the current document, find the first form on the page, and invoke the submit method for that form.&quot;

Here&#039;s a trick that draws it all together. Let&#039;s start with his form:

[xml]
&lt;form action=&quot;script.php&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;
&lt;input type=&quot;text&quot; name=&quot;submit&quot; /&gt;
&lt;/form&gt;
[/xml]

We can actually &quot;double up&quot;, as it were, on the namespaces, properties and methods, and call the following JavaScript, which would also submit the form:

[js]
document.forms[0].submit.form.submit();
[/js]

What &lt;code&gt;document.forms[0].submit.form.submit()&lt;/code&gt; says is, &quot;In the current page, get the first form [&quot;forms&quot; is a property of the document class; specifically, it is a collection of all the form objects in the current Web page]. Then, find the element within that form named &quot;submit&quot; [&quot;submit&quot; is the namespace for a text-type input element named, not coincidentally, &quot;submit&quot;]. Find that element&#039;s parent form [&quot;form&quot; is a property of the input class; it refers to the parent form which contains the input element]. Then, invoke the submit method for that form [&quot;submit()&quot; is a method of the form class; and again, we are calling that method via a reference to the form that contains the input element named &quot;submit&quot;].&quot;

Of course, for all that&#039;s worth, we could remove the input named &quot;submit&quot; and simply use &lt;code&gt;document.forms[0].username.form.submit()&lt;/code&gt;; or, for all that&#039;s worth, simply call &lt;code&gt;document.forms[0].submit()&lt;/code&gt;.

Elegance is always what we&#039;re after, and namespaces are primarily intended to group together our objects in a way that makes them easier to address. But as the examples above show, sometimes it&#039;s simpler and better to avoid using namespaces altogether and directly address collections as we would any array.</description>
		<content:encoded><![CDATA[<p>What Kiall describes is the difference between accessing a namespace member and calling a class method. It&#8217;s an example of why you should never use reserved words as a variable name, too.</p>
<p>In the case of his code example, <code>document.forms[0].submit</code> basically says, &#8220;in the current document, find the first form on the page, and give me the element in that form named &#8220;submit.&#8221; <code>document.forms[0].submit()</code> says, &#8220;in the current document, find the first form on the page, and invoke the submit method for that form.&#8221;</p>
<p>Here&#8217;s a trick that draws it all together. Let&#8217;s start with his form:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form action=&quot;script.php&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;
&lt;input type=&quot;text&quot; name=&quot;submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>We can actually &#8220;double up&#8221;, as it were, on the namespaces, properties and methods, and call the following JavaScript, which would also submit the form:</p>
<pre class="brush: jscript; title: ; notranslate">
document.forms[0].submit.form.submit();
</pre>
<p>What <code>document.forms[0].submit.form.submit()</code> says is, &#8220;In the current page, get the first form ["forms" is a property of the document class; specifically, it is a collection of all the form objects in the current Web page]. Then, find the element within that form named &#8220;submit&#8221; ["submit" is the namespace for a text-type input element named, not coincidentally, "submit"]. Find that element&#8217;s parent form ["form" is a property of the input class; it refers to the parent form which contains the input element]. Then, invoke the submit method for that form ["submit()" is a method of the form class; and again, we are calling that method via a reference to the form that contains the input element named "submit"].&#8221;</p>
<p>Of course, for all that&#8217;s worth, we could remove the input named &#8220;submit&#8221; and simply use <code>document.forms[0].username.form.submit()</code>; or, for all that&#8217;s worth, simply call <code>document.forms[0].submit()</code>.</p>
<p>Elegance is always what we&#8217;re after, and namespaces are primarily intended to group together our objects in a way that makes them easier to address. But as the examples above show, sometimes it&#8217;s simpler and better to avoid using namespaces altogether and directly address collections as we would any array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kiall</title>
		<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/#comment-133</link>
		<dc:creator>Kiall</dc:creator>
		<pubDate>Mon, 05 Jan 2009 19:45:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.dougv.com/blog/?p=346#comment-133</guid>
		<description>As a side note (which I&#039;ve just spent TOO long trying to figure out)â€¦

If any of the fields in the form have name of â€œsubmitâ€ eg then, the submit() method is no longer usableâ€¦ Continuing in the spirit of the article, I&#039;ll give the why:

Consider this form:

[xml]
&lt;form action=&quot;script.php&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;
&lt;/form&gt;
[/xml]

If you want to access the input field with a name of â€œusernameâ€ you can get to it with:

&lt;code&gt;document.forms[0].username&lt;/code&gt;

So when you add,

[xml]
&lt;input type=&quot;text&quot; name=&quot;submit&quot; /&gt;
[/xml]

you end up with a conflict:

&lt;code&gt;document.forms[0].submit&lt;/code&gt; wants to access the object relating to the form field with a name of submit, while &lt;code&gt;document.forms[0].submit()&lt;/code&gt; wants to access the form object and run its submit method

Kiall</description>
		<content:encoded><![CDATA[<p>As a side note (which I&#8217;ve just spent TOO long trying to figure out)â€¦</p>
<p>If any of the fields in the form have name of â€œsubmitâ€ eg then, the submit() method is no longer usableâ€¦ Continuing in the spirit of the article, I&#8217;ll give the why:</p>
<p>Consider this form:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form action=&quot;script.php&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;
&lt;/form&gt;
</pre>
<p>If you want to access the input field with a name of â€œusernameâ€ you can get to it with:</p>
<p><code>document.forms[0].username</code></p>
<p>So when you add,</p>
<pre class="brush: xml; title: ; notranslate">
&lt;input type=&quot;text&quot; name=&quot;submit&quot; /&gt;
</pre>
<p>you end up with a conflict:</p>
<p><code>document.forms[0].submit</code> wants to access the object relating to the form field with a name of submit, while <code>document.forms[0].submit()</code> wants to access the form object and run its submit method</p>
<p>Kiall</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Humble Servant</title>
		<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/#comment-132</link>
		<dc:creator>Humble Servant</dc:creator>
		<pubDate>Wed, 15 Oct 2008 11:27:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.dougv.com/blog/?p=346#comment-132</guid>
		<description>You sir, are a life saver. Thank you so much for spreading the wisdom man- its hard to come by sometimes.</description>
		<content:encoded><![CDATA[<p>You sir, are a life saver. Thank you so much for spreading the wisdom man- its hard to come by sometimes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Golan</title>
		<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/#comment-131</link>
		<dc:creator>Golan</dc:creator>
		<pubDate>Thu, 14 Aug 2008 10:56:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.dougv.com/blog/?p=346#comment-131</guid>
		<description>This was so useful and present in such a clear and helpful way. Well done and thank you very much.</description>
		<content:encoded><![CDATA[<p>This was so useful and present in such a clear and helpful way. Well done and thank you very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>https://www.dougv.com/2008/06/19/some-insight-into-the-document-object-model-how-forms-are-stored-by-javascript/#comment-130</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Mon, 23 Jun 2008 18:26:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.dougv.com/blog/?p=346#comment-130</guid>
		<description>You&#039;re such a geek! Yes, you&#039;re my brother and I still love ya. Thankfully, you&#039;ve got an outlet for your vice! See you soon.</description>
		<content:encoded><![CDATA[<p>You&#8217;re such a geek! Yes, you&#8217;re my brother and I still love ya. Thankfully, you&#8217;ve got an outlet for your vice! See you soon.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

