1

Possible Duplicate:
Upload files using input type=“file” field with .change() event not always firing in IE and Chrome

I have the following code that successfully uploads a image using .submit()

// Photo Upload Form - AutoUpload
$('input#file').change(function() {
    var maxsize = '20971520';
    var fileExtension = $(this)
                            .val()
                            .split('.')
                            .pop()
                            .toLowerCase();

    if(this.files[0].size > maxsize) {
        $('h4#maxFileSizeExceeded').show();

    }else if($.inArray(fileExtension, ['gif','png','jpg','jpeg']) == -1) {
        $('h4#fileTypeNotAllowed').show();

    }else{
        if(pushState == '0') {
            $('div#uploadPercentage').hide();
            $('img#uploadGifLoaderHTML4').fadeIn('fast');
        }
        $('form#joinPhotoUploadForm').submit();
        jcrop_api.destroy();

        $('div#croppingBackgroundContainer').fadeIn(1000);
        $('div#cropBoxWrapper').css('margin-left', '0px');
    }
});

The issue I have is if the user requests the same file again there is no change and the submit doesn't fire.

Is there a way for the same file to be requested again or to know its the same file again or some sort of reset that can be done on the input type="file"?

********************* Update

      <form action="scripts/php/photo_processing.php?page=join&section=precrop" id="joinPhotoUploadForm" enctype="multipart/form-data">
        <input type="file" name="file" id="file"><br>
      </form>

user clicks a browse button and can select an image. If the user selects a different image the image will upload. However if the user selects the same image the .change() function doesn't fire at all. I assume because its retaining the same state as before.

thx

Community
  • 1
  • 1
Adam
  • 19,932
  • 36
  • 124
  • 207
  • `The user requests the same file again`. How does the user request it? just as an image in the browse? Does it get loaded into the page? Posting the script that shows the image to the user would help alot, because the problem might be there. – Deep Frozen Sep 11 '12 at 07:20
  • 1
    I guess you should clear the contents of file upload control on successful submission callback.It should work. – techie_28 Sep 11 '12 at 07:26
  • how do I clear the contents of the file upload control? – Adam Sep 11 '12 at 07:29

1 Answers1

0

If the same file is selected into the input[type=file] there is no call for the change event since there is no change. Add a button to fire your code again or use the submit event on the form.

Henrik Ammer
  • 1,889
  • 13
  • 26
  • I didn't want another button - just one to select and it fires from there. Is there a way to reset the input[type=file] post submit so the .change() will work again? – Adam Sep 11 '12 at 07:26
  • Yes, [someone already asked that](http://stackoverflow.com/questions/9011644/how-to-reset-clear-file-input). – Henrik Ammer Sep 11 '12 at 07:30
  • Even more so, you have duplicates of your own question [here](http://stackoverflow.com/questions/10214947/upload-files-using-input-type-file-field-with-change-event-not-always-firin) and [here](http://stackoverflow.com/questions/4150256/jquery-change-event-on-file-input-element-does-not-fire-if-the-file-selection). – Henrik Ammer Sep 11 '12 at 07:34