0

I am using an upload script that runs a function once the file is uploaded. I need this function to re-assign the value of a javascript variable. I need to re-assign "trackid" to the value that is inside my onComplete function. Can anyone help me out?

Edit: A little more explanation... I have 2 instances of this upload script on my page. I need to take the response from the first uploader and assign it as a URL parameter to the 2nd uploader. Does it have something to do with the document.ready? I will update my code.

1st script:

<script type="text/javascript">
trackid = 9999999;
</script>
<script type="text/javascript">
        jQuery(document).ready(function() { 

    $('#mainftp').uploadify({
    'uploader'  : 'js/uploadifyposted/uploadify.swf',
    'script'    : 'js/uploadifyposted/uploadify.php?<?php echo urlencode("privateFolderWav=" . $privateFolderWav . "&userid=" . $userid. "&songid=" . $songid);?>',
    'multi'         : true,
    'auto'          : true,
    'height'        :   '32', //height of your browse button file
    'width'         :   '250', //width of your browse button file
    'sizeLimit' :   '51200000',  //remove this to set no limit on upload size
    'simUploadLimit' : '3', //remove this to set no limit on simultaneous uploads
    'buttonImg' : 'img/browse.png',
    'cancelImg' : 'img/cancel.png',
        'folder'    : '<?php echo $privateFolderWav;?>', //folder to save uploads to
        onProgress: function() {
          $('#loader').show();
        },
        onComplete: function(event, queueID, fileObj, response, data, trackid) {
          $('#loader').hide();
          $('#allfiles').load(location.href+" #allfiles>*","");
          $('#filesUploaded').attr('value', ''+response+'');
          trackid = response;
          alert(trackid);

          //location.reload(); //uncomment this line if youw ant to refresh the whole page instead of just the #allfiles div
        }   
    });

    $('ul li:odd').addClass('odd');

}); 

</script>

2nd script:

<script type="text/javascript">


        jQuery(document).ready(function() { 

    $('#mainftp2').uploadify({
    'uploader'  : 'js/uploadifymultiple/uploadify.swf',
    'script'    : 'js/uploadifymultiple/uploadify.php?<?php echo urlencode("songid=" . $songid . "&userid=" . $userid . "&trackid=");?>'+trackid,
    'multi'         : true,
    'auto'          : true,
    'height'        :   '32', //height of your browse button file
    'width'         :   '250', //width of your browse button file
    'sizeLimit' :   '51200000',  //remove this to set no limit on upload size
    'simUploadLimit' : '3', //remove this to set no limit on simultaneous uploads
    'buttonImg' : 'img/browse.png',
    'cancelImg' : 'img/cancel.png',
        'folder'    : '<?php echo $multiFolder?>', //folder to save uploads to
        onProgress: function() {
          $('#loader2').show();
        },
        onComplete: function(event, queueID, fileObj, response, data) {
          $('#loader2').hide();
          $('#allfiles2').load(location.href+" #allfiles2>*","");
          $('#filesUploaded2').attr('value', ''+response+'');

          //location.reload(); //uncomment this line if youw ant to refresh the whole page instead of just the #allfiles div
        }   
    });

    $('ul li:odd').addClass('odd');

}); 

</script>
5
  • I don't get it, what variable do you want trackid to contain within onComplete? Commented Sep 19, 2011 at 4:36
  • So what is the problem you are having? Commented Sep 19, 2011 at 4:36
  • What you have should be working fine. Its properly written. What should this modified global variable do once it's changed? Commented Sep 19, 2011 at 4:44
  • Why do you need a global? Always state the overall goal in addition to the step you're having problems with. Globals are usually the Wrong Thing. With asynchronous code (such as AJAX), continuation passing is the high road. Commented Sep 19, 2011 at 4:50
  • I need to pass the "response" from script 1 to a URL parameter in the 2nd. Commented Sep 19, 2011 at 4:57

2 Answers 2

1

I'm not seeing a trigger in this code. It looks like both scripts run immediately once the page is loaded, if so, the second script isn't waiting for the variable reassignment. You should have that second function called in the onComplete of the first

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

Comments

0

Try setting:

trackid = 9999999;

instead of

var trackid = 9999999;

var foo = 'baa'; <- private variable foo = 'baa' <- global variable

For example:

`function print2() { var foo = 'baa'; }

print2(); alert(foo); `

don't print 'foo' is undefinied. ` function print2() { foo = 'baa'; }

print2(); alert(foo); ` print 'baa'

3 Comments

"VAR" doesn't make a variable private, where its declared determines its scope. All leaving out "var" does is make it indistinguishable as to whether you're declaring a new variable or changing the value of a preexisting one.
Except that the var trackid is executed in global scope, making trackid a global variable. Declaring a variable with var only makes it local in function scope.
I have updated my question with more information. Thanks for your assistance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.