Solved

unterminated string constant javascript error and line wrapping in html

Posted on 2008-06-24
2
1,882 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

770 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