null return by getElementById method in JavaScript
<p>null return by getElementById method in JavaScript</p>

<pre><code>&lt;html&gt;
&lt;head&gt;

&lt;title&gt;test_elementObject&lt;/title&gt;

&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
        var input1 = document.getElementById ( "input1" );
        input1.value = "sample text"
//--&gt;
&lt;/script&gt;


&lt;/head&gt;

&lt;body&gt;

&lt;input id = "input1" type = "text" value = "" /&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I'm new in JavaScript 
why the script cause error: "input1 is null"?</p>
