Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

unterminated string constant javascript error and line wrapping in html

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

856 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