Jump to content

jQuery function onclick scope issue


anderson_catchme

Recommended Posts

$(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

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();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.