title: Form validation for textfield not working?
body: <p>In javascript, I´m supposed to create a function that checks if a textfield within a form is empty. If it is and the user clicks submit, the user will not be allowed to proceed. I found what I considered a suitable solution to this on w3schools (<a href="http://www.w3schools.com/js/js_validation.asp" rel="nofollow">http://www.w3schools.com/js/js_validation.asp</a>). I´ve checked more times than I can remember and everything seems to be in order, but it´s not working!! Instead, when the submit button is clicked, the website calls a different function I have in javascript which it is not supposed to do...</p>
  
  <p><strong>HTML code</strong></p>
  
  <pre><code>Other code
  &lt;p&gt;
     &lt;form method="post" name="form" action="" onsubmit="return validateName()"&gt;
     &lt;label for="fullName"&gt;Namn: &lt;/label&gt;&lt;input id="fullName" class="text" name="namn" type="text"&gt; &lt;/input&gt;
  &lt;/p&gt;
  &lt;p&gt;
     &lt;label for="epost"&gt;Epost: &lt;/label&gt;&lt;input id="epost" class="text" name="epost" type="email"&gt; &lt;/input&gt;
  &lt;/p&gt;
  &lt;p&gt;
     &lt;input id="submit" type="submit" value="Skicka"&gt; &lt;/input&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  Other code
  </code></pre>
  
  <p><strong>Javascript code</strong></p>
  
  <pre><code>function validateName() {
     var a = document.forms["form"]["namn"].value;
     if (a == null || a == "") {
        alert("Name required");
        return false;
     } else {
        return true;
     }
  }
  </code></pre>
  
  <p>Clicking the submit button should call this function above (validateName), but instead it calls this function:</p>
  
  <pre><code>function alert() { 
     return confirm("Do you really wish to leave this website?");
  }
  </code></pre>
  
  <p>I´ve looked through my code multiple times and can´t find anything that seems to be out of place. Can any of you find anything wrong? And maybe suggest a solution that solves my problem so my function will work properly? </p>
  
  <p>I would be very grateful if someone could help me resolve this matter!</p>