What is the difference between these codes?
<pre><code>&lt;input type='text' id='txt' name='txtName' size='20' value='testing'/&gt;

&lt;script type="text/javascript" language='javascript'&gt;
  var val = document.getElementsByName('txtName');
  alert(val[0].value);
  alert(window.txtName.value);
&lt;/script&gt;
</code></pre>

<p>In above code we are using</p>

<pre><code>alert(val[0].value);

alert(window.txtName.value);
</code></pre>

<p>these two ways for getting value from object. What is the difference between both ways and which way is best.</p>
