title: Populate JavaScript Array With Required Form Fields
body: <p>Is there a way to populate a JavaScript array with form fields that have the <code>required</code> attribute?</p>
  
  <p>I tried this bit of code...</p>
  
  <pre><code>var requiredfields = new Array();
  
  function getInputs() {
      var fields = document.getElementsByTagName('input');
      for (var i = 0; i &lt; fields.length; i++) {
          alert('I am input field ' + i);
          //var required = fields[i].getAttribute('required');
          if (fields[i].getAttribute('required')) {
              fields[i].style.border = '1px solid #ff0000';
              requiredfields.push(fields[i]);
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately, it's not even putting the border or showing the alerts.  I'm not really even sure if <code>getElementsByTagName</code> is returning the data, correctly.</p>
  
  <p>It's probable that my code is wack.  Hehehe...</p>