Add text to metabox input text field from Thickbox

What your code in;

jQuery(document).ready(function(){

// your code here...

});

…and in fact your code should look like this;

jQuery(document).ready(function($){

    $('.insertdownload').click(function(){

    var did = 'this is only a test';

    did=did.replace('download-', '');

    if ($('#format').val('1')) {

    $('#my_new_field').val('[download id="' + did + '" format="' + 

    $('#format').val() + '"]');

    } else {

    $('#my_new_field').val('[download id="' + did + '"]');

    }

    window.parent.tb_remove(); 

    });

});
​

Check out the Fiddle here… LINKAGE