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: 15
'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: 13
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: 15
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: 13
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: 15
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
  #8  
Old November 24th, 2008, 03:35 AM
andreicsd andreicsd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 8 andreicsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 2 sec
Reputation Power: 0
I had the same problem too. But only in IE; FF worked just fine.

Trying to put up some ajax, i needed to update some divs with html using js.

When js creates html (as var i mean), the html contains also some js (some alerts) that contains some new lines, like \n , and give me an error 'Unterminated String Constant'.

Removing the \n s resolved the problem, though i really need them.

I don't know about you guys, but i have problems with IE almost every time.

Reply With Quote
  #9  
Old February 18th, 2009, 03:18 AM
krunalbarot krunalbarot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 1 krunalbarot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 31 sec
Reputation Power: 0
Very Urgent

Hi all,

I am using Request.Form and take a text which has new line characters in that. but in javascript it throws the error at the end of first line i.e by encountering new line.

Can anyone tell how to get the whole text with the newline in it???

Please reply asap.

Thanks,
Krunal

Reply With Quote
  #10  
Old March 11th, 2013, 03:59 AM
JJLoubser JJLoubser is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 1 JJLoubser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 51 sec
Reputation Power: 0
Same problem with this

I get this error in this Javascript line of code and do not see any problem, please help:
---
if (SearchTypeSelected == "Type Of Camp/Event") {

if (SelectionListTypeOfCampBool == false) {


cell = row.insertCell(0);
cell.innerHTML = '<asp:label ID="LabelTypeOfCampEvent" runat="server" Width="200px" Text="Type Of Camp/Event:" CssClass="textblock"/>';
cell = row.insertCell(1);
cell.innerHTML = '<aspropDownList style="width:149px" Height="22px" Font-Name="Trebuchet MS" ID="mTypeOfCampEvent" runat="server" CssClass="textBox"><asp:ListItem Value="-1">Select</asp:ListItem><asp:ListItem>Holiday Camp</asp:ListItem><asp:ListItem>Winter Camp</asp:ListItem><asp:ListItem>Tiener Kamp</asp:ListItem><asp:ListItem>Manne Kamp</asp:ListItem><asp:ListItem>Other</asp:ListItem></aspropDownList >';
document.getElementById("SearchTypesBlock").appendChild(table);

SelectionListValue += "TypeCamp_";
SelectionListValueTeller++;

}

}
---

Reply With Quote
  #11  
Old March 14th, 2013, 02:13 AM
rcmvashd rcmvashd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 4 rcmvashd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 13 sec
Reputation Power: 0
which is the error it brings. Check for apostrophes inside the HTML.URLURLURLURLURLURL

Reply With Quote
  #12  
Old April 4th, 2013, 06:59 AM
Sadiutra Sadiutra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Location: usa
Posts: 5 Sadiutra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 8 m 20 sec
Reputation Power: 0
Send a message via Skype to Sadiutra
You made numerous nice ideas there. I done a search on the issue and learnt nearly all peoples will agree with your blog. Itís a wonder more people arenít trying it out.

Reply With Quote
  #13  
Old May 13th, 2013, 07:42 PM
Ronal2dduff Ronal2dduff is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2013
Posts: 8 Ronal2dduff User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 37 sec
Reputation Power: 0
That should remove all "enters" off your code, as to leave it in a single line!!



Reply With Quote
  #14  
Old August 14th, 2013, 05:24 AM
JasminePearce JasminePearce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2013
Posts: 1 JasminePearce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 52 sec
Reputation Power: 0
My code is working fine for other browser, but IE is showing and JavaScript unterminated string constant error. I am not getting what might be the reason for this.

Reply With Quote
Reply

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


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap