title: Generating a random number in JavaScript and passing it to an HTML input tag
body: <p>My script, stored as a separate js file:</p>
  
  <pre><code>function randomNumber(len) {
      var randomNumber;
      var n = '';
  
      for(var count = 0; count &lt; len; count++) {
          randomNumber = Math.floor(Math.random() * 10);
          n += randomNumber.toString();
      }
  
      return n;
  }
  
  var finalSequence = randomNumber(9);
  
  document.write('&lt;INPUT TYPE=TEXT NAME="ACCOUNT" VALUE='+finalSequence +' MAXLENGTH=16 SIZE=16&gt;');
  </code></pre>
  
  <p>I have included this <code>td</code> tag in my html file:</p>
  
  <pre><code>&lt;td align=left&gt;&lt;FONT FACE="Arial,Helvetica"&gt;&lt;script src="nexgen.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Do you suggest that I write my script inside the html file itself?</p>
  
  <p>I would like to display the generated random number using an <code>input</code> tag, such as that below. How do I do this?</p>
  
  <pre><code>&lt;INPUT TYPE=TEXT NAME="ACCOUNT" VALUE= ???  MAXLENGTH=16 SIZE=16&gt;
  </code></pre>
  
  <p>Update:</p>
  
  <p>I am combining the JavaScript and html in one html file as follows. Please see if you can find any mistakes because the number generated is not being displayed on html page.</p>
  
  <p>Javascript part:</p>
  
  <pre><code>function randomNumber(len) {
      var randomNumber;
      var n = '';
  
      for(var count = 0; count &lt; len; count++) {
          randomNumber = Math.floor(Math.random() * 10);
          n += randomNumber.toString();
      }
  
      document.getElementById("ACCOUNT").value = n;
      return n;
  }
  </code></pre>
  
  <p>HTML part:                                                            </p>
  
  <pre><code>&lt;tr&gt;
    &lt;td&gt;&lt;FONT FACE="Arial,Helvetica" color="red"&gt; Transaction ID: &lt;/font&gt;&lt;/td&gt;
    &lt;td align=left&gt;
      &lt;FONT FACE="Arial,Helvetica"&gt;
        &lt;script&gt; randomNumber(9); &lt;/script&gt;
        &lt;INPUT TYPE=TEXT NAME="ACCOUNT" ID="ACCOUNT" VALUE="" MAXLENGTH=16 SIZE=16 readonly&gt;
      &lt;/font&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>