i have a bunch of meta boxes in my wordpress theme. on the click of a button w/ class="meta_upload_button" i want to launch the default media uploader. thanks to some online tutorials I have that part mostly working. i am trying to adapt the code to work for multiple input/button pairs.
<input type="text" />
<button type="button" class="meta_upload_button">Upload</button>
ids, names and values are all dynamically generated by the WPAlchemy MetaBox class.
the problem it that my code is changing the value on the last text input field no matter which button i click on, which makes me think it is a jquery selection problem. however i used my fancy color debugging method and applied a border color to the input box that precedes the button clicked. that works just fine. but in the send_to_editor function the same declaration doesn't select the right input.
var ww = $('#post_id_reference').text();
$('.meta_upload_button').each(function() {
var button = $(this);
$(this).click(function() {
//test- result= changes border color on correct input
button.prev('input').css("border","3px solid red");
window.send_to_editor=window.send_to_editor_clone;
tb_show('', 'media-upload.php?post_id=' + ww + '&type=image&TB_iframe=true');
return false;
});
//my version of the send_to_editor
window.send_to_editor_clone = function(html){
//grabs the URL of the selected image
imgurl = $('img',html).attr('src');
forminput = button.prev('input');
//changes the value on the LAST input
forminput.val(imgurl);
tb_remove();
}
}); //end each