JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 5th, 2005, 12:29 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
'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

Reply With Quote
  #2  
Old February 5th, 2005, 06:18 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
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.

Reply With Quote
  #3  
Old February 6th, 2005, 04:13 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
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

Reply With Quote
  #4  
Old February 6th, 2005, 01:37 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 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.

Reply With Quote
  #5  
Old February 8th, 2005, 11:51 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
Thanks...

It works fine..

Thanks
Neville

Reply With Quote
  #6  
Old April 9th, 2007, 03:05 PM
djheru djheru is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 djheru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 44 sec
Reputation Power: 0
Thanks, I had the same problem

Quote:
Originally Posted by nevillemehta
It works fine..

Thanks
Neville


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

Reply With Quote
  #7  
Old December 5th, 2007, 12:57 PM
Ferdey Ferdey is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 1 Ferdey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 55 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > 'Unterminated String constant' error in javascript!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway