tags:

views:

29

answers:

1

Hi. Currently I'm using Wordpress & creating my own metabox in the write post panel. I've got a script that adds a custom media upload button. When the user clicks 'insert into post' it inserts the image URL into a text box. However, I also want to display a live preview of this image & I would like the script to insert the URL also into an image src.

Here is the script that currently doesn't work:

jQuery(document).ready(function() {

jQuery('#upload_image_button').click(function() {
formfield = jQuery('#metaupload').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});

window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#metaupload').val(imgurl);
jQuery('#preview').attr('src').html(imgurl);
tb_remove();
}

});

IE 8 is giving the error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SU 3.28; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0) Timestamp: Sat, 28 Aug 2010 17:23:35 UTC

Message: Object doesn't support this property or method Line: 12 Char: 2 Code: 0 URI: http://www.matthewruddy.com/premiumslider/wp-content/plugins/premium-slider/js/metabox_upload.js?ver=3.0.1

Can anyone help? Thanks..

+1  A: 

Instead of using the .html() function try passing the value to the .attr() function::

jQuery('#preview').attr('src', imgurl);
Darin Dimitrov
Is it possible to user the .html() function? This works fine when replacing an image but not when there already is no image. The <img src="" /> tag is only shown if the custom field isn't empty (using PHP if). The custom field is only posted when the user updates the post however I want the image to display before this.
Matthew Ruddy