Reputation: 2087
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 !!!
Upvotes: -1
Views: 110
Reputation: 42333
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.
Upvotes: 2