Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1905
  • Last Modified:

unterminated string constant javascript error and line wrapping in html

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
andyrr1
Asked:
andyrr1
1 Solution
 
hieloCommented:
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
 
ncooCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now