title: How to validate a file input on client side (Javascript)
body: <p>I have a form stored in a javascript variable below:</p>
  
  <pre><code>var $fileImage = $("&lt;form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startImageUpload(this);' class='imageuploadform' &gt;" + 
  "&lt;label&gt; Image File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;" +
  "&lt;input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /&gt;&lt;/label&gt;&lt;/form&gt;
  </code></pre>
  
  <p>Now as you can see when the user clicks on the submit button, it submits to the 'startImageUpload' function which is below:</p>
  
  <pre><code>function startImageUpload(imageuploadform){
    $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
    $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
    sourceImageForm = imageuploadform;
        return true;
  }
  </code></pre>
  
  <p>What it does is that when the user clicks on submit, it displays a loading bar and uploads the form.</p>
  
  <p>Now what my question is that I want to perform a simple javascript validation where when the user clicks on the submit button in the form, it will check if the file either a 'png' or 'gif' file type. If it is correct file type, then display the loading bar and upload the form. If the file type is incorrect, then show a n alert stating file type is incorrect but don't show the loading bar and do not upload the form.</p>
  
  <p>Does anyone know how this can be coded. It is so I can use the example from one of your answers to then expand on it and use the javascript to validate on more file types and also file size so it will be very helpful if somebody can please help me.</p>
  
  <p>Thank You</p>