anderson_catchme Posted September 6, 2014 Share Posted September 6, 2014 $(document).ready(function() { var uploadObj = $("#fileuploader").uploadFile({ url:"upload.php", fileName:"myfile", }); }); I'm trying to call UploadObj.uploadFile(); on a click event. Removing the "var" to make the scope global works sort of but also throws errors. Not sure what to do. Help appreciated. Link to comment https://forums.phpfreaks.com/topic/290892-jquery-function-onclick-scope-issue/ Share on other sites More sharing options...
anderson_catchme Posted September 6, 2014 Author Share Posted September 6, 2014 More info here: https://github.com/hayageek/jquery-upload-file Link to comment https://forums.phpfreaks.com/topic/290892-jquery-function-onclick-scope-issue/#findComment-1490197 Share on other sites More sharing options...
anderson_catchme Posted September 7, 2014 Author Share Posted September 7, 2014 Ok so I've narrowed the problem: <script type="text/javascript"> function submitform() { document.myform.submit(); } </script> <script> $(document).ready(function() { uploadObj = $("#fileuploader").uploadFile({ url:"/jquery-upload-file-master/php/upload.php", fileName:"myfile", onSuccess:function(files,data,xhr) { $('.ajax-file-upload-statusbar').delay(2000).slideUp('slow'); //Problem lies here with submitform() submitform(); }, onError: function(files,status,errMsg) { $("#status").html("<font color='red'>Upload is Failed</font>"); } }); }); </script> <br/> <form name='myform' action="createnewpost.php?4" method="POST"> <button id='my_button' name='submit' value='submit' class='btn btn-primary' onclick="event.preventDefault(); uploadObj.startUpload();"> Create Post</button> </form> </body> </html> Narrowed the problem: The form submission was interfering with fileupload. Now I just need submit get the form with submitform(); Link to comment https://forums.phpfreaks.com/topic/290892-jquery-function-onclick-scope-issue/#findComment-1490223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.