-1

I am having a weird problem in html in both firefox 6 and IE 8

there is this line that is generated in Java Class

<a onclick="updateEventDataDiv('1. some text <br>2. some text <br>', event);" href="javascript:void(0)"> some text </a>

this is a link created dynamically in a Java Class that creates a JavaScript pop up when the link is clicked. The Java code is nothing special it just iterates through a list and concats the values to this HTML code.

The prob is when clicked I get a Javascript error.

Error: unterminated string literal
Source File: http://localhost:18080/xxx/xxx/xxx.htm?actionLink=xxxTable-controlLink&ascending=false&column=raisedAt&page=x
Line: 1, Column: 19
Source Code:
updateEventDataDiv('x value

and the arrow points to single quote just before the x.

The weird thing when I open up the firebug -> inspect element and look at the element, the quotes are pefectly closed AND if I change anything i.e. remove a white space, add a white space, remove quote or do anything on the fly using the firebug and then click the link it WORKS ! I can see the pop up

not just that the same java code in the production server and same HTML page generated works like charm.. no issues at all.. its something in my local dev env...

I am also getting 1 javascripit errors for the same page but neither firefox nor ie tells me any details about it nor the line number

and yes one more thing.. I saved the page and ran it in firefox.. same prob.. then edited.. deleted a white space somewhere in the line and it WORKED and keeps working I do not have to tweak it any more... then why the hell it does not works the way it should

NEED HELP.. have to make this work on my loca dev env !!!

5
  • Does the text contain a single quote? Escape the quotes in the text before putting it in Javascript. Commented Sep 6, 2011 at 12:10
  • 1
    "The weird thing when I open up the firebug" — don't look at Firebug, look at the raw HTML sent to the browser. Commented Sep 6, 2011 at 12:11
  • 1. I checked the raw html.. its fine ! Commented Sep 6, 2011 at 12:13
  • 2. yes there is a single quote in string but that is because it has to be sent as an arg to js function. Also, if you look carefully you would see that the whole Javascript call is wrapped inside a double quote .. it should not create a prob.. and if i comment that the JS won't work Commented Sep 6, 2011 at 12:16
  • 1
    @anonymous — If it was fine, then it would work, which it doesn't. Show us your actual code, not an example of some different code, not an error message which truncates the code, the actual code. Commented Sep 6, 2011 at 12:22

1 Answer 1

2

My guess is that string contains a new-line on the server-side - so that when it's spat out into the DOM it's treated as unterminated:

<a onclick="updateEventDataDiv('x value 
blah', event);" href="javascript:void(0)"> some text </a>

Would need to be

<a onclick="updateEventDataDiv('x value blah', event);" href="javascript:void(0)"> some text </a>

It's not invalid HTML but it is invalid javascript.

So you might need to strip out any newlines in your string server-side.

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

6 Comments

YOU ARE SO F***** RIGHT ! THATS EXACTLY IT LOOKS IN THE HTML
THE SINGLE LINE IS SPLIT IN TWO LINES ! but how can i fex that
well, if str is the string being spat out by the server, it would be something like str = str.replace("\n",""); before you then write it out to the page.
thats how it looked in the javacode result = "<a href=\"javascript:void(0)\"onclick=\" updateXXX('" + xxxData.toString() + "', event);\">" + xxxValue + "</a>";
the line was created in 2 different lines - are you refering to this split in the java code ?
|

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.