
|
View Full Version : javascript tooltip, php problems.
e-zone 07-12-2008, 10:39 AM Hey, im trying to add a javascript tooltip "window" to a url that is being made in php, and i cant get it working.
This is how i create the url in php.
echo '<a href="' . $url . '">' . $title . '</a>';
And this is what i need to add to the url above:
onMouseover="fixedtooltip('the description', this, event, '150px')"
But where it says the description it should call this:
' . $desc . '
But when i try to put it together, it fails..
Any help is highly appreciated ;)
Dark Light 07-12-2008, 02:41 PM Can you post the code in its entirety and any error messages?
Regards,
Xeentech 07-12-2008, 05:28 PM Is it because you're ending the string by mistake? Try escaping the 's in the javascript arguments, like:
echo '<a href="' . $url . '" onmouseover="fixedtooltip(\'' + $desc + '\', this, event, \'150px\')">' . $title . '</a>';
e-zone 07-13-2008, 02:41 AM #Dark Light
It just shows a blank page..
This is the script: http://www.dynamicdrive.com/dynamicindex5/fixedtooltip.htm
And the rest of the code i use to grap the "desc"
private function _extract_feed_data()
{
$this->feed_title = $this->xml_obj->channel->title;
foreach ($this->xml_obj->channel->item as $item) {
$this->feed_title = str_replace(''', "'", $item->title); // Some itunes feeds use this.
$this->item_arr[] = array('timestamp' => strtotime($item->pubDate),
'title' => $this->feed_title,
'url' => $item->link,
'desc' => $item->description);
}
}
foreach ($data as $each) {
$date = date('D j M', $each['timestamp']);
$url = $each['url'];
$desc = $each['desc'];
$title = substr($each['title'], 0, 70);
if (strlen($each['title']) > 70) {
$title .= '...';
}
#Xeentech
Coulden get it to work, tryed diffrent options but no luck..
Dark Light 07-13-2008, 05:15 AM Have you successfully gotten the tooltip to work without the use of your PHP code? For example, directly writing the example code (along with the JavaScript include) to the browser?
<a href="http://www.javascriptkit.com" onMouseover="fixedtooltip('Comprehensive JavaScript tutorials and over 400+ <b>free</b> scripts.', this, event, '150px')" onMouseout="delayhidetip()">JavaScript Kit</a>
If so, can you output your version of the above JavaScript example and all error messages you receive?
Regards,
e-zone 07-13-2008, 05:24 AM Yes it works perfect normally..
Okay i got this one to work partly
<a href="' . $url . '" onMouseover="fixedtooltip(\' + $title + \', this, event)">
But when i hover over the link it just shows + $title + like it does not execute the php.
Is it impossible what im trying to do :think:
Dark Light 07-13-2008, 05:38 AM Assuming you are using an echo() statement to output your tooltip to the browser I would hazard a guess as to why it isn't working is because you're not using the correct quote marks and not using a dot instead of a +.
Try using something like this:
echo '<a href="' . $url . '" onMouseover="fixedtooltip(\'' . $title . '\', this, event)">';
That's very similar to Xeentech's example but it uses the correct dot instead of a +. If that works, replace $title with $desc.
Hope that helps,
e-zone 07-13-2008, 05:51 AM That work perfect, thanks :)
but now i see i have another problem with the way im calling the description $desc something not right with that one.
the $title function works perfect in the tooltip window.
the $desc "description" contains html char and other, should i use something like urlencode() ?
EDIT*deffently not urlencode :)
Dark Light 07-13-2008, 06:22 AM Glad that worked for you.
Can you please post an example of your $desc variable not working, or post a screenshot of the contents of the tooltip to illustrate your meaning? It's not terribly clear what you are trying to achieve and what you already have. :)
Regards,
e-zone 07-13-2008, 06:32 AM Yeah its really hard to explain sometimes, when i dont have so much knowledge to php, i know how i want it, but i lack of words :)
Im parsing an RSS script and the $desc (description) of the feed contains html such as & etc..
And when i tryed it with your code it would mess it up because it didden do something to the raw html, know what i mean ?
But now i got it working with this:
<a href="' . $url . '" onMouseover="fixedtooltip(\'' . htmlentities($desc) . '\', this, event)">
This was the solution:
htmlentities($desc)
And it works perfect! i hope its an okay solution to do it like that?
Thanks for your help :)
Regards S.A
Dark Light 07-13-2008, 06:38 AM So you had HTML code in your variable which was being spat out to the browser without being encoded. htmlentities() is indeed a very valid solution and turns characters such as < into strings like &something; but visually you will still see <. :)
Hope that helps and I'm glad your issues are now solved,
e-zone 07-13-2008, 06:43 AM Sounds good, once again thanks :)
e-zone 07-13-2008, 07:00 AM Oops just one problem, when the description contains
![CDATA[ The desciption.. ]]
many feeds use this, but it does not work together with htmlentities..
Any ideas?
*EDIT
Hmm seems like its something else, can whitespace, or break cause this problem, when i view source everything seems normal, but the ones that dosent show has a page break in the description.
Xeentech 07-13-2008, 09:44 AM Try using something like this:
That's very similar to Xeentech's example but it uses the correct dot instead of a +. If that works, replace $title with $desc.
Hope that helps,
D'oh.
Sorry about that e-zone, that's my hands thinking they're writing javascript.
|