title: input value undefined javascript
body: <p>I want to show an error message when text box is empty on submit, but is not working and everytime I try to get the value through the console area returns undefined.</p>
  
  <p>CSS</p>
  
  <pre><code>&lt;style&gt;
      #error_alert {
          visibility: hidden;
          border: 1px solid #F00;
          text-align: center;
          width: 100px;
      }
  
      label,
      input,
      button {
          display: block;
          margin: 2px;
      }
  &lt;/style&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>    &lt;script&gt;
      function validate() {
          var inputName = document.getElementsByName("fName")
          if (inputName.value == " ") {
              document.getElementById("error_alert").style.visibility = "visible";
          }
      }
      &lt;/script&gt;
  </code></pre>
  
  <p>Html</p>
  
  <pre><code>&lt;body&gt;
      &lt;h1&gt;Titulo&lt;/h1&gt;
      &lt;p id="error_alert"&gt;invalid name&lt;/p&gt;
      &lt;label&gt;Name:&lt;/label&gt;
      &lt;input type="text" name="fName" /&gt;
      &lt;label&gt;e-mail:&lt;/label&gt;
      &lt;input type="email"&gt;
      &lt;button onClick="validate()" type="button"&gt;Enviar&lt;/button&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>PS: When I added <code>x == null ||</code> as an opntion on the condition the message would turn visible everytime even when i had something written in the textarea.</p>