2

I am having a very weird error on this block:

<script type="text/javascript">
  var captions = new Array();
  captions[0] = "";
  captions[1] = '<div class="cap-desc"><h3>No Win - No Fee</h3><span class="captionSubhead">Performance Guarantee</span><br /><span style="color:#636363; font-size:13px;">Ask Today. We are very confident<br />you'll be impressed with our results! </span></div><br /><a href="http://#" class="rmore" target="_blank">read more</a>';
</script>

The error tells me that I am missing a ';' before captions[1] but I am pretty sure that captions[0] has a semi-colon!

The whole site is here: http://katron.sourcefit.com/cms02/a&a/

It has 5 captions now, but same error nonetheless. I tried changing the contents of the caption in question. In this case, it's captions[1] and it works. What is wrong with the caption? I am sure I am closing all tags and quotes and escaping \n to

7 Answers 7

7

You are not escaping a single quote properly...

captions[1] = '<div class="cap-desc"><h3>No Win - No Fee</h3><span class="captionSubhead">Performance Guarantee</span><br /><span style="color:#636363; font-size:13px;">Ask Today. We are very confident<br />you\'ll be impressed with our results! </span></div><br /><a href="http://#" class="rmore" target="_blank">read more</a>';

This just escapes the apostrophe in

you'll

Sign up to request clarification or add additional context in comments.

1 Comment

it's funny because stack overflow syntax highlighting already highlighted his error
5

The problem is you'll has an apostrophe and ends the code block. Make sure to escape it.

Comments

2

Found this question when I was googling the error.

My solution is not relevant to the original post but may help someone anyway.

I had forgotten the word function after a declaration:

Foo.bar(evt) {
    ...
}

should have been

Foo.bar = function(evt) {
    ...
}

Took me a little while to find this bug, so hopefully it helps someone.

Comments

1

The same error can occur if you are trying to add a property to an existing object prefixing with a var. For example

var existingObject = {};

var existingObject.property1 = {}; //will throw the same error

The solution is:

var existingObject = {};

existingObject.property1 = {}; //without prefixing with var

1 Comment

Ha! This was the reason for my error! Good to know.
0

That is because of single quote in last line at confident
you'll be impressed
repalce it with \' and it think that will fix it

Comments

0

you'll be impressed with our results!

That apostrophe (') in you'll is ending your string. So the javascript engine is looking for a semicolon there.

replace with \' to escape it

Comments

0

Check "you'll be impressed with our results! " in your captions[1] it has ' character which does not have escape character.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.