title: js call form value to variable
body: <p>Ok noobablicious question. But has had me sumped.</p>
  
  <p>Im declaring the value of a hidden form field with a Js script with in a function.</p>
  
  <p>e.g. These are just examples not the real script.</p>
  
  <pre><code>function myFunction(){
      var text = "hello world";
      var number = 12345;
  
  
  
      document.getElementById('text').value= text; 
      document.getElementById('number').value= number; 
  
    }
  </code></pre>
  
  <p>Then I want to be able to use the value of the form value as a variable in another script. I realize that there is the option to declare these variables globally. However I have heard that it is not as secure. Or a streamlined as I am going for.</p>
  
  <p>Second Script example...</p>
  
  <pre><code>    var autoText = document.getElementById('text').value;
      var autoNumber = document.getElementById('number').value;
  
      ...do stuff with variables.
  </code></pre>
  
  <p>However this is not working and returns undefined. Is this the correct DOM path to access the value of my form fields or do I need to find an attribute and its child??</p>
  
  <p>What other options are available to me??</p>
  
  <p>Thanks for your time. HTML is...
  </p>
  
  <pre><code>  &lt;form action="http://mysite/mypath" method="post"&gt;
  
    &lt;input type="text" name="text" id="text" value=""&gt;
    &lt;input type="text" name="text" id="number" value=""&gt;
    &lt;input type= "submit" name="go" value="go" allign="middle"/&gt;
    &lt;/form&gt; 
  </code></pre>
  
  <p></p>