title: Javascript - Object reference returning null even though it shoudn't
body: <p>I've got this:</p>
  
  <pre><code>var strBox = document.getElementById("txtSTR");
  var strModBox = document.getElementById("txtSTRMod");
  var refBox = document.getElementById("txtREF");
  var refModBox = document.getElementById("txtREFMod");
  var fortBox = document.getElementById("txtFOR");
  var forModBox = document.getElementById("txtFORMod");
  var intBox = document.getElementById("txtINT");
  var intModBox = document.getElementById("txtINTMod");
  </code></pre>
  
  <p>These vars all point to text boxes (read only) in my HTML document.</p>
  
  <p>They rely on populating their .value with the following array:</p>
  
  <pre><code>//0-STR, 1-REF, 2-FOR, 3-INT, 4-JUD, 5-CHA, 6-WIL, 7-TOU
  var charAttsAR = ["8","8","8","8","8","8","8","8"];
  </code></pre>
  
  <p>They are populated with the relevant array entry manually from a function called popDefDat() like this:</p>
  
  <pre><code>strBox.value = charAttsAR[0];
  strModBox.value = modSetter(charAttsAR[0]);
  
  refBox.value = charAttsAR[1];
  refModBox.value = modSetter(charAttsAR[1]);
  
  fortBox.value = charAttsAR[2];
  forModBox.value = modSetter(charAttsAR[2]);
  
  intBox.value = charAttsAR[3];
  intModBox.value = modSetter(charAttsAR[3]);
  </code></pre>
  
  <p>....and so on</p>
  
  <p>My issue is that strBox, strModBox, refBox and refModBox all initialise their data fine. However, at fortBox, it throws "fortBox is null" and I have no idea why. The code is identical, I have my script loaded just before the end of my  tag and I also have:</p>
  
  <pre><code>//initialise default data when page loads
  window.onload = popDefDat()
  </code></pre>
  
  <p>Honestly, I'm stuck. Any advice appreciated.</p>
  
  <p>Here's the html too:</p>
  
  <pre><code>&lt;form id="form3" name="form3" method="post" onsubmit="return false" action=""&gt;    
  &lt;p&gt;&lt;label&gt;&lt;/label&gt;&amp;nbsp;
  &lt;label for="lblHeadATT"&gt;&lt;/label&gt;
  
  &lt;input name="lblHeadATT" type="text" disabled="disabled" id="lblHeadATT" value="Points" readonly="readonly" /&gt;
  
  &lt;label for="lbHeadMOD"&gt;&lt;/label&gt;
  
  &lt;input name="lbHeadMOD" type="text" disabled="disabled" id="lbHeadMOD" value="Mod" readonly="readonly" /&gt;
  
  &lt;label for="txtPointBuy"&gt;&lt;/label&gt;
  
  &lt;input name="txtPointBuy" type="text" id="txtPointBuy" readonly="readonly" /&gt;
  </code></pre>
  
  <p></p></p>
  
  <pre><code>&lt;p&gt;Strength: 
  &lt;label for="txtSTR"&gt;&lt;/label&gt;
  &lt;input name="txtSTR" type="text" id="txtSTR" readonly="readonly" /&gt;
  &lt;label for="txtSTRMod"&gt;&lt;/label&gt;
  &lt;input name="txtSTRMod" type="text" id="txtSTRMod" readonly="readonly" /&gt; 
  
  &lt;input type="button" name="Btn_StrMinus" id="Btn_StrMinus" value="-" onclick="FNCstrSub()" /&gt;
  
  &lt;input type="button" name="Btn_StrPlus" id="Btn_StrPlus" value="+" onclick="FNCstrPlus()"/&gt;
  </code></pre>
  
  <p></p></p>
  
  <pre><code>&lt;p&gt;Reflex:
  &lt;label for="txtREF"&gt;&lt;/label&gt;
  &lt;input name="txtREF" type="text" id="txtREF" readonly="readonly" /&gt;
  &lt;label for="txtREFMod"&gt;&lt;/label&gt;
  &lt;input name="txtREFMod" type="text" id="txtREFMod" readonly="readonly" /&gt;
  
  &lt;input type="button" name="Btn_RefMinus" id="Btn_RefMinus" value="-" onclick="FNCrefSub()" /&gt;
  
  &lt;input type="button" name="Btn_RefPlus" id="Btn_RefPlus" value="+" onclick="FNCrefPlus()"/&gt;
  </code></pre>
  
  <p></p></p>
  
  <pre><code>&lt;p&gt;Fortitude: 
  &lt;label for="txtREF"&gt;&lt;/label&gt;
  &lt;input name="txtFOR" type="text" id="txtREF" readonly="readonly" /&gt;
  &lt;label for="txtFORMod"&gt;&lt;/label&gt;
  &lt;input name="txtFORMod" type="text" id="txtFORMod" readonly="readonly" /&gt;
  &lt;input type="button" name="Btn_ForMinus" id="Btn_ForMinus" value="-" onclick="FNCforSub()" /&gt;
  &lt;input type="button" name="Btn_ForPlus" id="Btn_ForPlus" value="+" onclick="FNCforPlus()"/&gt;
  &lt;/p&gt;
  
  &lt;p&gt;Intellect: 
  &lt;label for="txtINT"&gt;&lt;/label&gt;
  &lt;input name="txtINT" type="text" id="txtINT" readonly="readonly" /&gt;
  &lt;label for="txtINTMod"&gt;&lt;/label&gt;
  &lt;input name="txtINTMod" type="text" id="txtINTMod" readonly="readonly" /&gt;
  &lt;input type="submit" name="Btn_IntMinus" id="Btn_IntMinus" value="-" onclick="FNCintSub()"/&gt;
  &lt;input type="submit" name="Btn_IntPlus" id="Btn_IntPlus" value="+"onclick="FNCintPlus()" /&gt;
  </code></pre>
  
  <p>I've yet to write the tags for the other text boxes and buttons as I was hoping to solve this before carrying on.</p>
  
  <p>Thanks</p>