|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
'Unterminated String constant' error in javascript!
Hey,
Well i am trying to pass this string (basically HTML code) to a javascript function. Something like this: functionX('I need to pass the HTML code here!!!'); Now, say there is a variable called 'buffer' (i am using PHP code) which contains the entire HTML code which needs to be passed to this function. So now the code looks like this: functionX('<?=$buffer?>'); This particular line is throwing a javascript error which says 'Unterminated String constant'. I think i know the reason why this is happening. Basically you need the string to be all in one line and the indentation, spaces etc etc in the HTML code are causing this error. Can someone help me? Even PHP code to accomplish the same is welcome! Thanks, Neville |
|
#2
|
|||
|
|||
|
Hey Nevile... I think your problem relies on the HTML source. When you do <?= you replace it with all remaining inside the variable. So if the HTML has an ' in it, javascript would consider it the end of string an you would have an extra ' at the end of your code, which is the error it brings. Check for apostrophes inside the HTML..
Good Luck! Anibal. |
|
#3
|
|||
|
|||
|
I've tried this...
Hey,
Thanks for the reply. I have a file called 'data.txt' from where i extract the HTML and save it in the $buffer variable (in php). My code throws an error when data.txt looks like this: <table> <tr> <td bgColor="#ffffff"> </td> </tr> </table> It does NOT throw an error when data.txt looks like this: <table><tr><td bgColor="#ffffff"></td></tr></table> There are NO apostrophes in the HTML code for sure... Any solutions? Maybe some method in javascript that could convert the HTML code all into one line? Thanks Neville |
|
#4
|
|||
|
|||
|
Hey Nevillemehta! Ok, so it wasn't the apostrophies! I work with ASP...honestly, I don't know much about PHP. But, here's a posible solution (In PHP - the best I could find):
Try using the str_replace function as $buffer = str_replace(Chr(13), "", $buffer); If not Chr(13), check for the correspondent code...it can be End Of Line, Carriage Return, etc...and then, you pass it to the javascript. That should remove all "enters" off your code, as to leave it in a single line!! Good Luck, let me know how it worked.. Anibal. |
|
#5
|
|||
|
|||
|
Thanks...
It works fine..
Thanks Neville |
|
#6
|
|||
|
|||
|
Thanks, I had the same problem
Quote:
Hey, thanks. I was having the same problem using FCKeditor along with PHP to store the code in a MySQL database. When pulling the data out and assigning it to the value variable in the javascript function for FCKeditor, I would get the same problem due to the line breaks |
|
#7
|
|||
|
|||
|
blanks space in String (.Net)
Hello everyone I had the same problem at a .Net Web Page and i was sending a string like '12/4/2007 6:36:00AM' then replacing by '12/4/20076:36:00AM' , my script works fine !!
Anibal ..Thanks for the tip ![]() F3r |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > 'Unterminated String constant' error in javascript! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|