As you say it's in your JavaScript code rather than as an attribute on an HTML element,
onchange="document.getElementById('user_name').value =
document.getElementById('theDomain').value + '\\' +
document.getElementById('fake_user_name').value"
Is setting a string value, delimited by "". As the \\ is in a string, the value of the string is
document.getElementById('user_name').value =
document.getElementById('theDomain').value + '\' +
document.getElementById('fake_user_name').value
which means that when that string is run as code, it is no longer valid - there is only one backslash, which escapes the closing single quote.
Either double-escape the back-slash ('\\\\'):
onchange="document.getElementById('user_name').value =
document.getElementById('theDomain').value + '\\\\' +
document.getElementById('fake_user_name').value"
or use a function as an event handler instead of an evaluated string.
'\\\\'.+ '-' +? What if you just useddocument.getElementById('theDomain').value? How do you explain your code working in the link I gave?