Solved

unterminated string constant javascript error and line wrapping in html

Posted on 2008-06-24
2
1,874 Views
Last Modified: 2012-06-27
Hi,

I have a problem with some javascript - I have some PHP which prints out a number of links with an onMouseOver event as below.....where for some records, the description seems to start on a new line and generates an unterminated string constant error.

Is there any way of managing where the source wraps - I've tried putting \n charachters part way through the description but the "As systems accountant" bit always seems to start on the next line.  I'm pretty sure that text doesn't have any strange starting characters.

HTML source produced

<a class="article_link" alt="Click to view or edit" href="editarticle.php?type=9&id=61" onMouseOut="HideHelp('desc61');" onMouseOver="ShowHelp('desc61', '','
As Systems Accountant you will be responsible for developing this legal firm&#8217;s primary reporting system and implementing other accounting syst...');">
SYSTEMS ACCOUNTANT</a>



The PHP code if it helps is.....

                 $text = substr(strip_tags($desc_query_data[$query_data["fieldname"]]), 0, 150);
                 $text = str_replace("'", "", $text);
                  print "   <td valign=\"top\" class=\"".$row_type."\">\n<a class=\"article_link\"\n alt=\"Click to view or edit\" href=\"editarticle.php?type=".$type."&id=".$rec_id."\" onMouseOut=\"HideHelp('desc".$rec_id."');\"\n onMouseOver=\"ShowHelp('desc".$rec_id."', '','".$text."...');\">\n".$field_values[$fields_to_display[$counter]]."</a><div style=\"display:none\" id=\"desc".$rec_id."\"></div></td>\n";
0
Comment
Question by:andyrr1
2 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 21857438
try:
                 $text = substr(strip_tags($desc_query_data[$query_data["fieldname"]]), 0, 150);

                 $text = str_replace("'", "", $text);

			  $text = str_replace("\n","\\n",$text);

                  print "   <td valign=\"top\" class=\"".$row_type."\">\n<a class=\"article_link\"\n alt=\"Click to view or edit\" href=\"editarticle.php?type=".$type."&id=".$rec_id."\" onMouseOut=\"HideHelp('desc".$rec_id."');\"\n onMouseOver=\"ShowHelp('desc".$rec_id."', '','".$text."...');\">\n".$field_values[$fields_to_display[$counter]]."</a><div style=\"display:none\" id=\"desc".$rec_id."\"></div></td>\n";

Open in new window

0
 
LVL 15

Accepted Solution

by:
ncoo earned 320 total points
ID: 21857462
Try the following.

$newstr = str_replace(array("\r\n", "\n", "\r"), '\n', $str);

Place it where ever you have text with a new line for use by javascript.

Like below:
 $text = substr(strip_tags($desc_query_data[$query_data["fieldname"]]), 0, 150);

                 $text = str_replace("'", "", $text);

                  print "   <td valign=\"top\" class=\"".$row_type."\">\n<a class=\"article_link\"\n alt=\"Click to view or edit\" href=\"editarticle.php?type=".$type."&id=".$rec_id."\" onMouseOut=\"HideHelp('desc".$rec_id."');\"\n onMouseOver=\"ShowHelp('desc".$rec_id."', '','".str_replace(array("\r\n", "\n", "\r"), '\n', $text)."...');\">\n".$field_values[$fields_to_display[$counter]]."</a><div style=\"display:none\" id=\"desc".$rec_id."\"></div></td>\n";

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now