Question

I'm walking you through a processs here:

Step 1
1. Select product from dropdownlist
2. A form is populated with data
3. An hidden ID get's the product ID from the selected item
4. Uploadify is initialized and retrieves the product ID. An uploadbutton is added to form.

Step 2
1. Select new product from dropdownlist
2. The form is re-populated with data
3. The hidden ID get's the new product ID from the selected item
4. Uploadify is initialized and retrieves the product ID. A new uploadbutton is added to form.

Now I'm stuck with two buttons. Not exactly what I want.

I could check to see if the button is added and thus not re-initialize the button, but then the Uploadify script will not retrieve the new product ID (which I need for misc. stuff).

Any ideas how I could solve this little issue?

This is my uploadify function:

function initUploadify()
{ 
    // If button is already added, do not add it again.
    // But this will not retrieve new productID.
    if( jQuery('#brand_btnBrowseLogoQueue').length < 1)
    {
        jQuery('#txtBoxFileName').css({'position':'relative', 'top':'-9px'});
        jQuery("#brand_btnBrowseLogo").uploadify({
            'uploader'       : 'wp-content/plugins/uploadify/uploadify.swf',
            'script'         : 'wp-content/plugins/uploadify/uploadify.php',
            'folder'         : 'brand',
            'fileExt'        : '*.jpg;*.jpeg;*.png',
            'auto'           : true,
            'multi'          : false,
            'method'         : 'POST',
            'height'         : '30',
            'width'          : '100',
            'buttonImg'      : 'path/to/img/btn_browse_101x30px.png',
            'scriptData'     : {'productID':jQuery("#productID").val()},
            onComplete       : function(event, queueID, fileObj, response, data) { 
                //This makes the json response readable                
                data = eval("(" + response + ")");
                //Update logo image
                setLogo(jQuery("#brandID").val(),data.fileName);
            }
        });
    }    
}
Was it helpful?

Solution

If you just need to change the productID this should do it according to the plugin documentation

//initialize uploadify when first product is selected
if( jQuery('#brand_btnBrowseLogoQueue').length < 1) {
   ...
} else {
    //uploadify already initialized just change the productId
    $("#brand_btnBrowseLogo").uploadifySettings(
        'scriptData',
        {'productID': jQuery("#productID").val()}
    );
}

OTHER TIPS

Have you tried removing the previous button before creating a new one?

if($('#brand_btnBrowseLogoQueue').length != 0)
    $('#brand_btnBrowseLogoQueue').remove();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top