View Full Version : Resolved Javascript Tooltip Code-breaking Bug

12-14-2009, 10:50 PM
Hello! I come to you guys with a javascript problem. I'm using the javascript mouseover called wz_tooltip.js located here (http://www.walterzorn.com/tooltip/tooltip_e.htm).
Inside of it, I'm using many variables which have worked perfectly fine. If any variable has a value that conflicts with javascript, I simply do a php str_replace. This has worked perfectly for all but one issue. When one of the $string has a breaking line in it <br />, it breaks the javascript mouseover entirely. I can't figure this out for the life of me. The mouseover code itself is bolded:

$placeholders = array("'", "<br />");
$fixup = array("\'", "TEST");

$saPreview2 = str_replace($placeholders, $fixup, $lastxdevel2['pagetext']);

$lastxdevelt2.="<div class='smallfont'><font size='2'><a onmouseover=\"Tip('<b>Title:</b> $saTitle2<br/><b>User:</b> $lastxdevel2[lastposter]<br /><b>Last Post:</b>$agdate2<br/><b>Preview: </b>$saPreview2')\" onmouseout=\"UnTip()\" href='showthread.php?t=$lastxdevel2[threadid]'>$lastxdevel2[title]</a></font></div>";

I tested with other values to make sure that the strings were properly being replaced, and indeed they were. I have the mouseover tooltip set to a specific width. So multiple lines work fine (one line running into another), but if there is a <br /> inside or any form of a formal line break, it literally causes the javascript mouseover script to cease to function. This is impossible to avoid because $string's value is text from a forum post.

I'll reiterate that the str replace is working. When I view source, there are no <br/> tags. There are still line breaks though.

Why would line breaks in $string cause a javascript mouseover to cease functioning? I have a feeling it must be how the tooltip handles line breaks? Thank you in advance.

Old Pedant
12-15-2009, 03:57 AM
Can you show us a LIVE example of it not working? So we can see it after the PHP has been substituted in?

12-15-2009, 12:16 PM
I'm working on localhost. Give me a minute to set it up on my server with some examples. I'll edit this post in about 10 minutes. :thumbsup:

Edit: Nevermind, problem was related to \n. :)