I can't tell if I'm misunderstanding the syntax or if I'm not understanding the concept. I want to take a javascript variable and concatenate it into a URL parameter inside a jQuery function. The variable is reassigned by another upload script's jQuery function.

<script type="text/javascript">
var trackid = 12;


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>
share|improve this question

71% accept rate
feedback

1 Answer

up vote 0 down vote accepted

Check the location of your double-quotes, you're missing one inside the PHP fragment, and have an extra one at the end of the URL.

script: 'js/uploadifymultiple/uploadify.php?<?php echo urlencode("songid=" . $songid . "&userid=" . $userid . "&trackid=);?>'+trackid+'"',

First we'll focus on the part we know is wrong:

'uploadify.php?<?php echo urlencode("songid=" . $songid . "&userid=" . $userid . "&trackid=);?>'+trackid+'"',

The question mark is after the .php part. songid and userid seem fine.

'uploadify.php?<?php echo urlencode("&trackid=);?>'+trackid+'"',

Oh crap, where's the closing quote in our call to urlencode?

'uploadify.php?<?php echo urlencode("&trackid=");?>'+trackid+'"',

So now we have a string that's part JavaScript, part PHP, and it's right.

'uploadify.php?etc&trackid=' + trackid + '"',

But URLs don't have trailing quotes, so there must be an extra.

'uploadify.php?etc&trackid=' + trackid,
share|improve this answer
I'm having a hard time debugging this. Any chance you could write out what you mean? – user547794 Sep 19 '11 at 2:27
Done. Hope that clears things up. – Dave Newton Sep 19 '11 at 9:33
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.