title: How to make a script execute on page load?
body: <p>I am trying to create a HTML script that will pick a random number out of a list I have given when someone loads the page. This means if they refresh the page a new number will appear. I know how to generate a script that shows a random word/number when you press a button but it is necessary to make the number generate itself and also it can't be in a wordbox. If anyone can help me with this, I'd appreciate it.</p>
  
  <p>I don't know much about coding but from the information I've gathered, here's what I have constructed:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
       &lt;title&gt;&lt;/title&gt;
  &lt;SCRIPT LANGUAGE="JavaScript"&gt;
  &lt;!--
  // Use the following variable to specify
  // the number of random words
  var NumberOfWords = 32
  
  var words = new BuildArray(NumberOfWords)
  
  // Use the following variables to
  // define your random words:
  words[1] = "2,719"
  words[2] = "2,718"
  words[3] = "2,717"
  words[4] = "2,715"
  words[5] = "2,713"
  words[6] = "2,711"
  words[7] = "2,710"
  words[8] = "2,709"
  words[9] = "2,708"
  words[10] = "2,706"
  words[11] = "2,704"
  words[12] = "2,702"
  words[13] = "2,701"
  words[14] = "2,700"
  words[15] = "2,699"
  words[16] = "2,698"
  words[17] = "2,696"
  words[18] = "2,694"
  words[19] = "2,692"
  words[20] = "2,690"
  words[21] = "2,688"
  words[22] = "2,686"
  words[23] = "2,685"
  words[24] = "2,683"
  words[25] = "2,681"
  words[26] = "2,678"
  words[27] = "2,675"
  words[28] = "2,673"
  words[29] = "2,671"
  words[30] = "2,669"
  words[31] = "2,667"
  words[32] = "2,664"
  function BuildArray(size){
  this.length = size
  for (var i = 1; i &lt;= size; i++){
  this[i] = null}
  return this
  }
  
  document.addEventListener("DOMContentLoaded", 
  function PickRandomWord(frm) {
  // Generate a random number between 1 and NumberOfWords
  var rnd = Math.ceil(Math.random() * NumberOfWords)
  
  // Display the word inside the text box
  frm.WordBox.value = words[rnd]
  })
  //--&gt;
  &lt;/SCRIPT&gt;
  
  &lt;CENTER&gt;
  &lt;FORM NAME="WordForm"&gt;
  &lt;INPUT TYPE=TEXT SIZE=50 NAME="WordBox"&gt;&lt;BR&gt;
  &lt;/CENTER&gt;
  &lt;/FORM&gt;
  
  &lt;body&gt;
  &lt;big&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
  &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;/span&gt;&lt;/big&gt;&lt;/big&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is it doesn't work and I don't know why.</p>