Javascript Error: Expected ‘)’ Code 0 Line xxx Character xxx IE Only

Are You Receiving Me ?

Our corporate website is rendered in about 8 different languages across maybe 30 different domains (thus 30 websites), so our content is multi-lingual ranging from Thai to Arabic to English. A DropDownBox on the HomePage for each website gives the user the option to see the page in any language available to that domain.

Our Sources Of Javascript
The content itself is stored in a massive DataSet keyed to Page/Section/SubSection/Language/Domain. The Pages are rendered dynamically with each SubSection (can be as small as a few HTML-styled words) doing a look up to the DataSet from Markup in order to retrieve its Language/Domain specific content. The content can include any HTML including inline Javascript

Here’s an example from our Markup (i.e.aspx Page)
div id="OtherServiceBanner"
h4 %=WebContentDictionary.OtherServiceBannerTitle% /h4

Apart from inline Javascript we have the usual external js files.

Error Time

So our Web Designers report a JS error occurring on our French Language websites only. The error only occurs in IE.

I excluded the external JS files but the error still occurred, so then, using faithful old Divide and Conquer I progressively commented out all the calls to our Content DataSet until the error disappeared.

It didn’t take too long. The error was in some inline Javascript inserted by our Web Content Management Team whose understanding of HTML and Javascript is not immense.

Here’s the bad Javascript:
a id="ColContent" onclick="return myJSFunction('Visite virtuelle d’un bureau équipé',this.href);"

You will notice that the onclick attribute includes an embedded single quote character in d’un, so IE parsed this as return myJSFunction(‘Visite virtuelle d’ and complained about the ‘missing’ right parenthesis “)”

To correct the issue, the onclick attribute was edited like so :
onclick=”return myJSFunction(‘Visite virtuelle d&aposun bureau équipé’,this.href);”>

That &apos is the way you use an embedded apostophe (single-quote) in Javascript

Bottom line: when you get Expected ‘)’ in your Javascript error, look for improperly terminated string literals and make sure you account for all your sources of Javascript. Then use Divide and Conquer to find the culprit. You’ll probably find you need to use &apos., if not you’ll have to make other plans for Nigel.

Advertisements

Tags:

10 Responses to “Javascript Error: Expected ‘)’ Code 0 Line xxx Character xxx IE Only”

  1. Paul Chambers Says:

    Thankyou baraholka1

    Indeed this was the cause of a similar issue I had when building XML feeds.

    A timely reminder of the values of adequate data filtering prior to use.

    Cheers

  2. Vinod Kumar Says:

    Thanx baraholka1 !!!

    nice solution

  3. Guest Says:

    great find, good tip, saved time with this article, thanks baraholka1

  4. Kat Says:

    Great tip, thank you so much!

    I was experiencing the same issue, also only in the French language version of the site I was working on. I was totally baffled. I checked the code and replaced any strings containing apostrophes with the html entity number.

    • baraholka1 Says:

      KAT,

      Ultra-Heureux je pouvais aider à mon vieux genre gluant de tadpole-y de cire de manière.
      Mai votre aéroglisseur soit jamais plein des anguilles,

      Tout le meilleur,

      Barra

  5. Quang Says:

    This is really a time saving post and it’s also a nice debug teaching one, through. Thank you a lot for this.

    • baraholka1 Says:

      Quang,

      Thankyou for your kind remaarks.
      May I kindly point out that you have spelt “ftp” incorrectly in your email address ?

      – Baraa The Pedant

  6. Babu Says:

    This article really saved lot of my time. Nice teaching article. Thank you very much.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: