1

Hi I need to save a variable in Javascript and give it to uploadify.

This is my code:

var mediaID;

$(".edit_photo_media").live("click", function() {
    mediaID = $(this).data("media-id");
    $.ajax({
        url: 'edit.php?action=media_select',
        type: 'GET',
        dataType: 'html',
        success: function (select) {
            if (select == '3') {
                document.location = "login.php";
            } else {
                $("#dialog_upload_media").dialog("open");
            }
        }
    });
    return false;
});

$('#file_upload').uploadify({
    'fileTypeDesc' : 'Image Files',
    'fileTypeExts' : '*.jpg;',
    'fileSizeLimit' : '4096KB',
    'debug'    : true,
    'method'   : 'post',
    'formData'      : {'id' : '' + mediaID},
    'swf'      : 'include/swf/uploadify.swf',
    'uploader' : 'include/scripts/upload_mult.php'
}); 

So everytime before the uploader is opened .edit_photo_media is clicked.

<a href="#" data-media-id="'.$getID[$i].'" data-table="Media" class="edit_photo_media" title="Foto hochladen"><img src="images/photo.png" /></a>

This is where the var mediaID is getting its content. Inside .edit_photo_media mediaID is defined correct.

But if I click the upload button mediaID is undefined. Why is the variable loosing its value?

Edit: Ok this seems to be related to a uploadify bug? If I check mediaID on any other function it is working fine... rlly strange

2
  • You could try $(this).attr("data-media-id"); instead of $(this).data() Commented Jun 16, 2012 at 20:01
  • Im getting same undefined result with $(this).attr("data-media-id"); Commented Jun 16, 2012 at 20:10

2 Answers 2

4

Ok problem solved. Just added 'onUploadStart' and saved the id in there

$('#file_upload').uploadify({
    'fileTypeDesc' : 'Image Files',
    'fileTypeExts' : '*.jpg;',
    'fileSizeLimit' : '4096KB',
    'buttonText'    : 'Bilder auswählen',
    'debug'    : true,
    'method'   : 'post',
    'formData' : {'id' : 0},
    'swf'      : 'include/swf/uploadify.swf',
    'uploader' : 'include/scripts/upload_mult.php',
    'onUploadStart' : function(file) {
        $('#file_upload').uploadify("settings", "formData", {"id": mediaID});
    }
}); 
Sign up to request clarification or add additional context in comments.

Comments

0

jQuery only started subsuming HTML5 data properties set in the source code from version 1.6 onwards. If you're using < 1.6, this won't happen, in which case upgrade jQ.

Comments

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.