where do i place function below for validation
<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>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>Below is the validation, but my question is where do I place the code so that when the user clicks on the "Upload" button, if incorrect file type then alert appears and it doesn't upload file, if file type is correct then it displays loading bar and uploads file.</p>

<pre><code>$(".imageFile").change(function() {

    var val = $(this).val();

    switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
        case 'gif': case 'jpg': case 'png':
        return true;
            break;
        default:
            $(this).val('');
            alert("not an image");
            return false;
            break;
    }
});
</code></pre>
