why is it uploading image when it shouldn't do?
<p>I have a problem where if the file extension is incorrect, it displays an alert. This works fines but the problem is that it shouldn't upload the file. Why is it uploading the file because in the function below I have stated that if imageValidation is passed, then go onto the 'startUploadImage()' function to start uploading:</p>

<pre><code>function imageClickHandler(imageuploadform){ 
      if(imageValidation(imageuploadform)){ 
          return startImageUpload(imageuploadform); 
      } 
      return false;
  }
</code></pre>

<p>Below is the imageValidation() code where it checks for file extension:</p>

<pre><code>function imageValidation(imageuploadform) {

    var val = $(imageuploadform).find(".fileImage").val();
    switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
        case 'gif':
        case 'jpg': 
        case 'jpeg':
        case 'pjpeg':
        case 'png':
             return true;

        case '':
            $(imageuploadform).find(".fileImage").val();
                     alert("To upload an image, please select an Image File");
            return false;

        default:
             alert("To upload an image, please select a valild file extension.");
             return false;

    }

    return false;

}
</code></pre>

<p>I don't know if you need to see the startImageUpload function but if you do then this is also below:</p>

<pre><code>function startImageUpload(imageuploadform){

  $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
  $(imageuploadform).find('.imagef1_cancel').css('visibility','visible');
  $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
  sourceImageForm = imageuploadform;

      return true;
}
</code></pre>

<p>Code showing the form:</p>

<pre><code>var $fileImage = $("&lt;form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='imageClickHandler(this);' class='imageuploadform' &gt;" +

    "Image File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;&lt;label&gt;" +

    "&lt;input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /&gt;&lt;/label&gt;" + 

    "&lt;/p&gt;&lt;p class='imagef1_cancel' align='center'&gt;&lt;label&gt;" +

    "&lt;input type='button' name='cancelImageBtn' class='cancelimage' value='Cancel' /&gt;&lt;/label&gt;" + 
    "&lt;/p&gt;&lt;/form&gt;");
</code></pre>
