Jump to content


Photo

javascript - adding formatted text to mouseover


  • Please log in to reply
4 replies to this topic

#1 Hooch

Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 03 November 2010 - 11:01 AM

Hey all.
I am trying to create a mouseover (of an image)that generates text within <span> tags.
The text is html formatted and could include images, links etc.
Here is how I tried to code..
<a href="<?PHP echo $image;?>" onmouseover="document.getElementById('myText').firstChild.data = '<?PHP echo stripslashes($r2['description']);?>';return true;" title=""><img alt="<?PHP echo $r2['item_name'];?>" src="<?PHP echo $thumb;?>" height="" width="" class="last" /></a>
These links are dynamic and come from a DB.
Unfortunately the content in $r2['description'] is screwing up the mouseover code.

Any help is greatly appreciated.

Thank you.

***EDIT***
I have fixed this issue

Edited by Hooch, 03 November 2010 - 06:26 PM.


#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 04 November 2010 - 11:27 PM

Out of curosity, what was the fix? My first assumption would have been a quote of some kind inside of the description.

#3 Hooch

Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 08 November 2010 - 12:36 PM

Hey RC.
I went a little different route.
echo '<a href="'.$image.'" onmouseover="runthis(\''.htmlspecialchars($r2['description']).'\')" title=""><img alt="" src="'.$image.'" height="180" width="200" class="last" /></a>';
<script type="text/javascript">
/*<![CDATA[*//*---->*/

function runthis(str)
{
document.getElementById('myText').innerHTML = str;
}


/*--*//*]]>*/
</script>
echo '<span id="myText">&nbsp;</span>';

I am still working on a fix for the 1st method.
I know it will involve some single and double quote escaping.

#4 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 08 November 2010 - 06:23 PM

I'm liking the cleaner PHP in that second bit. I also like how you moved the text update stuff into a function (more maintainable solution).

If you can put up a live example of the first method you're still wanting to fix (or attach the final HTML), i'll see if i can't play with it for a bit and figure out what is wrong.

#5 Hooch

Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 10 November 2010 - 08:51 AM

Hi RC.
I'll send along some info in a day or two.
I'm in the process of selling/fixing up a house and it's
very time consuming right now.

Thanks for your interest!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users