title: Get value from text field and post it in a javascript variable
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element">Why does jQuery or a DOM method such as `getElementById` not find the element?</a>  </p>
  </blockquote>
  
  
  
  <p>I have this script:</p>
  
  <pre><code>&lt;script&gt;
  var dataoriginale = document.getElementById("savedataoriginale").value;
  &lt;/script&gt;
  </code></pre>
  
  <p>and this text field:</p>
  
  <pre><code>&lt;input name="savedataoriginale" id="savedataoriginale" type="text" value="testtest"&gt;
  </code></pre>
  
  <p>but when I try to print the javascript var</p>
  
  <pre><code>&lt;script&gt;document.write(dataoriginale)&lt;/script&gt;
  </code></pre>
  
  <p>I get undefined.</p>
  
  <p>Why? How can I fix that?</p>