View Full Version : problem characters

tyler jones
05-31-2005, 03:31 PM
I have a .net page and in .net, there's no way to easily set the value of a textbox that has it's property set to password. So, I figured a workaround would be to write some javascript to the page that populates that field after the page loads. This works fine except for one person's password that contains a "\" character. So, for example, their password is E032\j1 and after I populate it, I alert the value and get E032j1. Is there a way to make sure that any character in the password is populated instead of removed? Thanks.

Bill Posters
05-31-2005, 04:05 PM
The backslash is read by the browser as an escape character, meaning that the character that follows the backslash should be taken literally (rather than interpreted as a special character).
To get the backslash to appear as part of a string - in this case, your password - escape it (i.e. escape the backslash)

When you autofill the password value, escape the backslash, by placing a backslash before it.


document.forms[0].elements[0].value = 'E032\\j1';

When you alert that form field value, it should give the correct password, including the single backslash.

tyler jones
05-31-2005, 04:11 PM
Thank you, that worked fine.