Form onload with variables

I have a script that dynamically uploads files. The server then assigns them a random name and reports this back. It looks like this:

function upload_image_file(file, row)
{ var formData = new FormData();
  formData.append("userfile", file);
  var request = new XMLHttpRequest();
  img_upload_array[imgidx].uploadRequest = request;
  img_upload_array[imgidx].status = "uploading";"POST", "imgupload.php");
  request.onload = function () {
	img_uploading[imgidx] = imgidx;
	if (request.status === 200) { // successfully uploaded
	    len = myarray[row].length;
	    myarray[row][len] = request.responseText;

My question is about the row variable. This function can be called several times and the image should be assigned to the row with which it was linked when the function was called. I understand that this should be achieved with some kind of enclosure. Unfortunately my understanding of enclosures is still insufficient to pull this of.

Can somebody help me?

Hi @musicmaster, I’m afraid I don’t understand the problem… the row parameter never gets reassigned, so inside the onload callback it will still hold the same value as when the request was created (and it already does create a closure BTW).

In that case my problem is solved. Thank you for enlightening me.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.