title: File type validation with JavaScript
body: <p>I have a question regarding to JavaScript validation. I am validaing the <code>&lt;input type="file"&gt;</code> whenever my scripts runs, it validates but also the action page is called. I want to stop the action page until the validation is complete. Here is my code, any help will be awesome. Regards</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Image Uploading&lt;/title&gt;
      &lt;/head&gt;
  
  
      &lt;body&gt;
          &lt;form name="xx" action="server.php" method="post" enctype="multipart/form-data" onsubmit="Checkfiles(this)"&gt;
              &lt;input type="file" name="file_uploading" id="filename"&gt;
              &lt;input type="submit" value="Submit" name="uploadfile"&gt;
          &lt;/form&gt;
  
          &lt;form name="view" method="post"&gt;
              &lt;a href="view_server.php"&gt;View your uploaded Images&lt;/a&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;script type="text/javascript"&gt;
      function Checkfiles()
      {
          var fup = document.getElementById('filename');
          var fileName = fup.value;
          var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
  
      if(ext =="GIF" || ext=="gif")
      {
          return true;
      }
      else
      {
          alert("Upload Gif Images only");
          return false;
      }
      }
  &lt;/script&gt;
  </code></pre>