Error: my variable is null
<p>I have an error in my simple javascript code.</p>

<p>HTML</p>

<pre><code>&lt;input type="text" name="txt" id="txt" value="Hello" /&gt;
</code></pre>

<p>JavaScript</p>

<pre><code>&lt;script type="text/javascript"&gt;
 var txt = document.getElementById('txt').value;
 var txt2 = (null == document.getElementById('txt2').value)? "" : document.getElementById('txt2').value;
 alert(txt2);
&lt;/script&gt;
</code></pre>

<p>I know that the element called txt2 does not exist, but I want that if an element does not exist variable txt2 will be assigned a default value</p>
