title: getElementsByName() not working?
body: <p>I have a Javascript function which should update a hidden input field in my form with a number that increments every time the function is called.</p>
  
  <p>It worked originally with <strong>getElementById()</strong> however because I had to redesign my form I cannot use the php function to assign an individual ID to the element so all I have is a unique name for that element.</p>
  
  <p>So instead I decided to use <strong>getElementsByName()</strong> from Javascript to modify the element.</p>
  
  <p>Here is the HTML of that element</p>
  
  <pre><code>  &lt;input type="hidden" value="" name="staff_counter"&gt;
  </code></pre>
  
  <p>This is my Javascript code:</p>
  
  <pre><code>window.onload=function()
  {
  
  //function is activated by a form button 
  
  var staffbox = document.getElementsByName('staff_counter');
                      staffbox.value = s;
  
  
                  s++;
  }
  </code></pre>
  
  <p>I am getting no errors on Firebug when the function is called and the input field is not getting a value given to it.</p>
  
  <p>It was working with getElementById() but why all of a sudden it does not work with getElementsByName()?</p>
  
  <ul>
  <li>-I have checked that it is the only unique element in the document.</li>
  <li>-I checked for any errors on Firebug when activating the function</li>
  </ul>
  
  <p>Here is the code I use from Codeigniter to make the element</p>
  
  <pre><code>// staff_counter is name and the set_value function sets the value from what is
  //posted so if the validation fails and the page is reloaded the form element does
  // not lose its value
  
  echo form_hidden('staff_counter', set_value('staff_counter'));
  </code></pre>
  
  <p>Thanks</p>