So it turns out I had a few unecessary variables in here.
- I didn’t need to define
formfield
as a var because it’s unused. I defined it twice. - Because there are two functions sharing common variables, it’s best that I nest the
window.send_to_editor
within each of the click functions.
This is the final version of both the jQuery functions ( the source of the problem)
jQuery('#upload_doc_button').live('click', function() {
window.send_to_editor = function(html) {
var docurl = jQuery(html).attr('href');
jQuery('#wpa_upload_doc').val(docurl);
tb_remove();
}
tb_show('Upload Publication', 'media-upload.php?TB_iframe=1&width=640&height=263');
return false;
});
jQuery('#upload_image_button').click(function() {
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#upload_image').val(imgurl);
tb_remove();
}
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});