In my javascript code I have
onchange="document.getElementById('user_name').value =
document.getElementById('theDomain').value + '\\' +
document.getElementById('fake_user_name').value"
here backslash doesn’t work. What is the problem?
How should I write it?
example:
I want to have “x.com\joe” by using domain name(x) and fakeusername (joe) but the result I get is just joe when I use ‘\’
As you say it’s in your JavaScript code rather than as an attribute on an HTML element,
Is setting a string value, delimited by
"". As the\\is in a string, the value of the string iswhich 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 (
'\\\\'):or use a function as an event handler instead of an evaluated string.