title: Cannot set Border of Undefined - JS
body: <p>I'm trying to validate some code via javascript. The drama I am having is that I receive an </p>
  
  <blockquote>
    <p>"Uncaught TypeError: Cannot set property 'border' of undefined". </p>
  </blockquote>
  
  <p>I am new to javascript and trying to get a full understanding of why this happens and how to prevent this in future coding projects. My goal is if the validation fails it changes the text box border to red. </p>
  
  <pre><code>function validation_Step1(event) {
      var Firstbox = document.getElementsByName("Firstbox");
  
      if (Firstbox.value == null || Firstbox.value == '') {
          document.getElementsByName("Firstbox")
              .style.border = "2px solid red";
          alert("Error");
          return false;
      } else {
          return true;
      }
  }
  </code></pre>