You need to escape the single quotes in your output string.
Example:
document.write('There\'s an escaped single quote in that text');
More info about js strings and escaping you find here:
How to Escape Quotes in a String using JavaScript | bobbyhadz[
^]
[Edit]
Final example with text in the question (tested and it works):
document.write('<button style="width:100;height:20" onClick="window.location=\'/scripts/broker.exe?_program=websas.COMPLAINTS_input6.sas&_debug=0&CCNUM=C0000582\'">Upload Image</button> ')
There are two single quotes which you need to escape:
\'/scripts/broker.exe?_program=websas.COMPLAINTS_input6.sas&_debug=0&CCNUM=C0000582\'