views:

836

answers:

2

I'm pretty new to javascript and jQuery. I'm using Uploadify to upload images to the server. There are multiple Uploader objects on the page. I need to pass the id of the Uploader object being used to the server. This is what I have so far:

$('input.ImageUpload').uploadify({
    ...
    'scriptData': {'id': ??????},
    ...
});

How can I make this happen? I've tried "this.id" and "$(this).attr('id')". Am I even going about this in the correct way?

A: 

I'm not sure if this is ideal, but this is what I ended up doing:

$('input.ImageUpload').each(function() {
  $(this).uploadify({
    ...
    scriptData({'id': $(this).attr('id')},
    ...
  });
});
Jacob Mason
A: 

This is how I use it successfully:

$(document).ready(function() {
    $(".upload").each(function() {
        $(this).uploadify({
            'uploader'      : '/code/js/jquery.uploadify/example/scripts/uploadify.swf',
            'script'        : '/code/js/jquery.uploadify/example/scripts/uploadify.php',
            'cancelImg'     : '/code/js/jquery.uploadify/example/cancel.png',
            'folder'        : '<?=$upload_path?>' + $(this).attr('id'),
            'queueID'       : 'fileQueue',
            'auto'          : true,
            'multi'         : false,
            'scriptData'        : ({'var_name': 'this_var_value'}),
            'fileDesc'          : 'Images and PDF files only! (JPG, PNG, PDF)',
            'fileExt'               : '*.pdf;*.jpg;*.jpeg;*.png',
            'buttonText'        : 'browse' +  $(this).attr('id')
        });
    });
});



<div id="fileQueue"></div>
<input class="upload" type="file" name="ImageUpload" id="_ID_1" /><br />
<input class="upload" type="file" name="ImageUpload" id="_ID_2" /><br />
<input class="upload" type="file" name="ImageUpload" id="_ID_3" /><br />
Christian K.