0

Users upload image and thumbnail show up in the div OK, but when the value of the input change (update with Wordpress Media Uploader) it doesn't change the thumbnail by running the command after change, only the value in input will change. Thank you everyone in advanced.

Function i wanna fix:

/*Check for Favicon and Place it into Thumbnail*/
 var checkFaviconField = jQuery('#faviconImageURL').bind();
 if (checkFaviconField){
     jQuery('#favicon').append("<img height='48px' src='"+imageUrl+"'/>");
 }

Here is the full code:

var activeUpload = false;
jQuery(document).ready(function() {
    jQuery('.uploadButton').click(function() {
        activeUpload = true;
        retrievefieldID = jQuery(this).prev().attr('id');
        Fields = jQuery('#'+retrievefieldID).attr('name');
        tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');

        if (activeUpload == true) {
            var previousFunction = window.send_to_editor;
            window.send_to_editor = function (html) {
                imageUrl = jQuery('img', html).attr('src');
                jQuery("#"+retrievefieldID).val(imageUrl);
                tb_remove(); 

                /*Check for Favicon and Place it into Thumbnail*/
                var checkFaviconField = jQuery('#faviconImageURL').bind();
                if (checkFaviconField){
                    jQuery('#favicon').append("<img height='48px' src='"+imageUrl+"'/>");
                }
            }
        }
        activeUpload = false;
    });
});

1 Answer 1

2

.bind() only attaches (or binds) an event handler to an element. It does not trigger the event on the element. To trigger the change function, use .trigger() with the event name or use the shorthand .change().

Samples:

jQuery('#faviconImageURL').trigger('change');

jQuery('#faviconImageURL').change();
Sign up to request clarification or add additional context in comments.

7 Comments

I have tried that, but it does't run the code again. :/ it just change the value in the input.
is there a way after first time the code runs, it stead by for another action in same function?
Where are you binding the change event to the element? Also, what are you trying to access with checkFaviconField? The jQuery object?
I thought thats the way you set it up so it can check if change happened. and then put it in if statement and run the code if it is true.
Is #faviconImageURL a dynamically generated element?
|

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.