开发者

Problem with uploadify jQuery and javascript

So I'm using uploadify to upload multiple images to a folder. Along with each upload, I want to pass alon开发者_开发知识库g 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"/>


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() });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜