Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I'm using uploadify to upload multiple images to a folder. Along with each upload, I want to pass along a 'batch name' from a text box value.

When I hard code the batch_name (Fire) below, the database updates fine, but when I replace 'fire' with $('#batch_name').val() the value doesn't seem to pass.

javascript

<script type="text/javascript">
$(document).ready(function() {
    $("#uploadify").uploadify({
        'uploader'       : 'uploadify/uploadify.swf',
        'script'         : 'uploadify.php',
        'scriptData'     : {'session_id': '<?php echo session_id(); ?>', 'batch_name': 'Fire'},
        'cancelImg'      : 'cancel.png',
        'queueID'        : 'fileQueue',
        'auto'           : false,
        'multi'          : true
    });
});
</script>

textbox

<input type="text" name="batch_name" id="batch_name"/>
share|improve this question

1 Answer

up vote 2 down vote accepted

You are grabbing the value of batch_name at document.ready, when (I'm guessing) the field is blank – the user hasn't had time to type a batch name when the DOM is first ready! ($('#batch_name').val() is evaluated before making (and in order to make) the call to .uploadify( ... ), not when the upload is submitted.)

In order for Uploadify to pass a batch name typed in to a field, you need to change the scriptData object before the upload is submitted.

$('#uploadify').uploadifySettings('scriptData', { 'session_id': '<?php echo session_id(); ?>', 'batch_name': $('#batch_name').val() });
share|improve this answer

Your Answer

 
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.