简体   繁体   中英

wordpress upload form javascript help

I have a custom template with custom admin panel, I have a image uploader using the wordpress media uploader in lightbox.

Here is the structure:

textbox 1 - browse 1
textbox 2 - browse 2
textbox 3 - browse 3

If I click on browse 1, the popup apears and if i click "insert into post" the lightbox media uploader will disappear and return a image url.

But the problem is the url appends n the 3 textbox and i only click on browse 1,. My expected result is if i click browse 1 it should be append in textbox 1 and so on.

Here is my code

jQuery('.op_upload_image_button').each(function() {
    jQuery(this).click(function() {
        formfield = jQuery(this).parent().find('.op_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');
        jQuery('.op_upload_image').val(imgurl);
        tb_remove();
    }
});
jQuery('.op_upload_image_button3').click(function() {
    jQuery(this).click(function() {
        formfield = jQuery(this).parent().find('.op_upload_image3').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('.op_upload_image3').val(imgurl);
        tb_remove();
    }
});

Just change class name for button and text field class.

Not sure from the question, but I wonder if this is because all three of the textboxes are .op_upload_image and this bit jQuery('.op_upload_image').val(imgurl); is referencing the last textbox?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM