title: JavaScript Not Working with HTML and PHP
body: <p>I'm trying to create a simple registration form with basic <code>HTML</code> and <code>PHP</code> to insert data to my database. Basically, I want to validate the fields first before inserting the data and so I have created an external <code>JavaScript</code> file. Problem is, it is displaying the actual <code>JavaScript</code> code on the next page as opposed to validating!</p>
  
  <p><strong>My HTML file:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Register Page&lt;/title&gt;
  &lt;body&gt;
  &lt;form id="register" method="POST" action="register.js" onsubmit="return verify()" action="register.php"&gt;
      Forename: &lt;input type="text" name="forename"&gt;&lt;br&gt;
      Lastname: &lt;input type="text" name="surname"&gt;&lt;br&gt;
      Password: &lt;input type="password" name="password"&gt;&lt;br&gt;
      &lt;input type="submit" value="Register"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>My JavaScript file:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function verify(){
          var forename = document.getElementById["forename"].value;
          if(forename == null || forename == ""){
              alert("Forename is empty");
              return false;
          }
      }
  &lt;/script&gt;   
  </code></pre>
  
  <p>Instead of just validating I'm being redirected to a new webpage showing me the code I have written above.</p>
  
  <p>I am completely new to web development and it would mean a lot if someone could help me out. All I want to do is just validate the fields before adding them to the database.</p>