0

This is my jquery code to upload multiple file. Input file generated dynamically so i am calling this FileUploader function where these input file generated. But I have to click twice to upload file. Any ideas are appreciated.

FileUploader: function($dis) {
                    var fileName = '';
                    var $htm = $($dis.parents('div.sfFormInput').find('div.cssClassUploadFiles'));
                    var $ht = $($dis.parent('div.uploader'));
                    var extension = new RegExp($ht.attr('extension'), "i");

                    var upload = new AjaxUpload($('#' + $dis.attr('id') + ''), {
                        action: Path + "UploadHandler.ashx",
                        name: "myfile[]",
                        multiple: true,
                        data: {},
                        autoSubmit: true,
                        responseType: "json",
                        onChange: function(file, ext) {
                        },
                        onSubmit: function(file, ext) {
                            if ($ht.attr('almul') == "false" && $('div.cssClassUploadFiles').children('div').length > 0) {
                                csscody.alert('<h1>Alert Message</h1><p>You can upload only one file at  a time!</p>');
                                return false;
                            }
                            if (ext != "exe" && extension != '') {enter code here
                                if (ext && extension.test(ext)) {
                                    this.setData({
                                        'MaxFileSize': $ht.attr('filesize')
                                    });
                                } else {
                                    csscody.alert('<h1>Alert Message</h1><p>Not a valid file!</p>');
                                    return false;
                                }
                            }
                        },
                        onComplete: function(file, response) {
                            var html = '';
                            var filePath = Path + "/UploadedFiles + file;
                            if (file.split('.')[1] == "jpg" || file.split('.')[1] == "JPEG" || file.split('.')[1] == "gif" || file.split('.')[1] == "bmp" || file.split('.')[1] == "png")
                                html = '<div title="' + Path + "UploadedFiles + file + '" ><img height="10%" width="10%" src="' + filePath + '"/><a class="sfDeleteFile"><img src="../Modules/FormBuilder/images/closelabel.png" /></a></div>';
                            else
                                html = '<div title="' + Path + "UploadedFiles + file + '" >' + file + '  <a class="sfDeleteFile"><img src="../Modules/FormBuilder/images/closelabel.png" /></a></div>';
                            $htm.append(html);
                        }
                    });
                }


Code works but only issue is I have to click twice to upload file.

5
  • twice on what button on the file browser or the upload button that opens the file browser ? Commented May 29, 2012 at 5:46
  • @shareef Upload Button.At runtime input file generate.I think there is some problem or ???? Commented May 29, 2012 at 5:50
  • How are you using your FileUploader? Are you binding any click event to the upload button? Include that code as well. Commented May 29, 2012 at 6:16
  • no I am not binding any click event to the upload button. Commented May 29, 2012 at 6:18
  • When are you triggering your upload function then? on form submit event? Commented May 29, 2012 at 6:28

1 Answer 1

1

The problem is not with the fileuploading part, rather looks like in the initialization part. If your file upload control is dynamically created make sure you initialize the uploader after binding that in your markup.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.