Jump to content

jQuery function onclick scope issue


anderson_catchme
 Share

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.

Edited by anderson_catchme
Link to comment
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();

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.