I'm new to Wordpress, and i'm developing a plugin. I'm havin some troubles with image upload...

Is there a way to call a JavaScript function in a onClick tag, that calls the Wordpress media uploader, and after the upload, saving the uploaded image link into a JavaScript variable? Without leaving the page, using thickbox.

Every single option i tried on google, leaves the page after the image upload.

function imageUpload() {
        formfield = jQuery('#upload_image').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');

and calling in the html using

<input onClick=\"imageUpload();\" id=\"upload_image_button\" class=\"alterar-logo onetarek-upload-button button\" type=\"button\" value=\"Upload Image\" />

It makes the upload, but when i click in "insert into post" it won't copy the variable

Using WP 3.6, by the way...

Edit: i managed to do it by removing return false;

  • Please show the code you tried and where it's failing. – kaiser Oct 28 '13 at 13:27
  • 1
    Updated the question, sorry... – ghaschel Oct 28 '13 at 13:36
  • No problem. Please go back once more and file another edit as the question still is very vague. So far I can't really imagine what you're trying to do. And moving that into my local dev stack wouldn't help much as it's not working code that I could test, build upon and help you with a solution (extension of your script). – kaiser Oct 28 '13 at 13:45
  • The only thing i'm trying to do is getting the path to the uploaded image (the one clicked in "insert into post" in the opened thickbox) saved in a variable. Not appending, not inserting, just the image path – ghaschel Oct 28 '13 at 13:47
  • Or move the return past send_to_editor. . . . Voting to close as too-localized or JavaScript issue. – brasofilo Oct 28 '13 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.