This post has focused on the upload form itself very closely. This form can be arrived at by the user under a couple of contexts depending on what form a user is uploading into/from which is why I attacked this problem from a differen perspective...
In the following context, I solved the setting of the target upload document library with a bit of jQuery scripting which I have demonstrated below.
This works for the scenario where a user has focused a rich text field in a "Add New Item" dialog window, which causes the "Insert" ribbon to appear. Following the users clicks to the upload button, jQuery extracts the select item from the hierarchy of iframes and sets the default library based on the value you want. Following the upload the link to the newly uploaded file is placed into the rich text field. (SharePoint 2013)
I have not tested this method in any other scenarios. I'm kind of new-ish to crafting jQuery client-side javascript so this probably can be written without nesting but it works!
<script language="javascript" src="[YOUR JQUERY SRC]"></script>
<script language="javascript">
$(window).load(function () {
var interval = 400
//console.log('Javascript Loaded'); // log the tracking of user clicks to debug input timing based on speed of site
$("[#SELECTOR FOR RICH TEXT FIELD]").on('click', function () {
console.log('Body Clicked!');
setTimeout(function() {
//console.log('Timeout 1 Fired.'); // log the tracking of user clicks to debug input timing based on speed of site
$("[#SELECTOR FOR INSERT RIBBON TAB]").attr('onClick', 'return true'); // must set attr of onClick to return true to allow jQuery .on('click') to fire
$("[#SELECTOR FOR INSERT RIBBON TAB]").on('click', function () {
//console.log('Insert Clicked!'); // log the tracking of user clicks to debug input timing based on speed of site
setTimeout(function() {
//console.log('Timeout 2 Fired.');
$("[#SELECTOR FOR UPLOAD BUTTON]").attr('onClick', 'return true');
$("[#SELECTOR FOR UPLOAD BUTTON]").on('click', function () {
//console.log('Upload Clicked!'); // log the tracking of user clicks to debug input timing based on speed of site
setTimeout(function() {
var pdoc = parent.document
$(pdoc).find("iframe").each(function() {
$(this).contents().find("select").each(function() {
if (this.name == "ctl00$PlaceHolderMain$SelectListSection$ctl01$AvailableDocLibs") { // this selector should be generic, you'll have to confirm this.
$(this).val("[HEX/GUID]"); // find the guid value corresponding to your library choice in the selector.
};
});
});
},interval * 2);
});
},interval);
});
},interval);
});
});
</script>