Apostrophe causing Javascript error

I am having a problem when users with apostrophe’s in their surname access a database. Users without apostrophe’s can acces the application no problem. When a user with an apostrophe in their surname accesses the application, a number of javascript errors occur and they are unable to go any further. Anyone every had this problem?

Subject: Apostrophe causing Javascript error

I’ve seen this. In my case it was caused by some ‘computed’ javascript. For example, you have a script in passthru html somewhere on the page or form. Embedded in the script is a field or some computed text containing the user’s name (@Username). The statement could be (for example):

name = ‘’;

At run time this would translate to:

name = ‘Tom McCann’;

This works ok, except when the name contains an apostrophe, the statement would be:

name = ‘John O’Boyle’;

That statement will not make sense to the script interpreter because it interprets the apostrophe after O as the string terminator. The characters after the terminating apostrophe do not make sense hence the errors you are getting.

Let me know if this is the case.

Subject: RE: Apostrophe causing Javascript error

I can almost guarantee that this is the problem. Since these parameters are usually set using Formula Language, there is a fairly simple solution. Instead of using this sort of thing:

“var name = '” + @Name([Abbreviate];@UserName) + “';”

use something more along these lines:

“var name = unescape('” + @URLEncode(“Domino”;@Name([Abbreviate];@UserName)) + “');”

That gets you around any potential problems, even those that may be caused by really, really stupid legal name changes. Note, too, that if the value is a property of some other object, like a field value, the apostrophe will be included as a literal.

Subject: RE: Apostrophe causing Javascript error

I am having the same problem as this and would be interested to know where the @URLEncode should go?

Subject: RE: Apostrophe causing Javascript error

@URLEncode does not encode apostrophes. That being the case, your code won’t do any better than the original posters.Instead, use @ReplaceSubstring to search for the apostrophe and add the javascript escape character (back-slash) in front of the apostrophe.

Try this…

"var name = '" + @ReplaceSubstring(@Name([Abbreviate];@UserName);"'";"\\'") + "';"

Subject: RE: Apostrophe causing Javascript error

I am having the same problem as this and would be interested to know where the @URLEncode should go?