Solved

Image show on rollover

Posted on 2004-04-23
7
1,201 Views
Last Modified: 2012-06-21
I have a page that has several links that are coming from a db.

Link1
Link2
Link3
etc...

I want to be able to rollover them and have a corrisponding image appear below.

Link1 - onMouseOver - Show image for link1
Link2 - ''              ''        ''          ''        link2
etc...

How can I do this?

I need to code this quickly...

0
Comment
Question by:alexhogan
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10902865
The following example has a single image which changes according to the link you are mousing over...

<html>
<head>
<title>Example</title>
<script language="Javascript">
<!--
function ChangeImage(ImageName,NewImage)
      {
            eval("document.images."+ImageName+".src=NewImage")
      }
//-->
</script>
</head>
<body>
<a href="#" onMouseOver="ChangeImage('Image','Image1.gif')">Link 1</a>
<a href="#" onMouseOver="ChangeImage('Image','Image2.gif')">Link 2</a>
<img name="Image" src="noimage.gif">
</body>
</html>
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10902966
Try some thing like this, use a blank .gif instead of null.

<script>
function setIm(imName){
document.getElementById('theImage').src=imName
}
</script>

<a href='http://google.com' onmouseover='setIm("http://experts-exchange.com/images/pe/143475.jpg")' onmouseout='setIm(null)'>Google</a>
<br><a href='http://Yahoo.com' onmouseover='setIm("http://experts-exchange.com/images/pe/344311.jpg")'  onmouseout='setIm(null)'>Yahoo</a>
<p>
<img id='theImage'>
0
 
LVL 8

Author Comment

by:alexhogan
ID: 10928988
I'm sorry it's taken a few days to get back to this quesiton.  Pulled in many directions.., you know.

How can I take those static image references and make them dynamic?  I have the links coming from a database and I won't know which links are going to be displayed to the browser.

The links are derived from product class codes and the images have been named the same as the class code for simplicity.

Because of the wait and need I am increasing the points.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10929227
What information comes from the DB - in the example below I have assumed that the link, image name and a description are coming from the db.

<html>
<head>
<title>Example</title>
<script language="Javascript">
<!--
function ChangeImage(ImageName,NewImage)
     {
          eval("document.images."+ImageName+".src=NewImage")
     }
//-->
</script>
</head>
<body>
<%Do while not rs.EOF%>
   <a href="<%=rs("LinkName")%>" onMouseOver="ChangeImage('Image','<%=rs("ImageName")%>')"><%=rs("LinkDescription")%></a>
   <%rs.MoveNext
Loop%>
<img name="Image" src="noimage.gif">
</body>
</html>

Hope that helps :)
0
 
LVL 8

Author Comment

by:alexhogan
ID: 10929312
On these rollovers there is no link, just a number.  (it's not my call.., client request)

These numbers are the class codes I mentioned.  When the user rollsover the link the image will appear at a predetermined location.

The images are in a dir underneath the calling file.  They are numbered the same as the class codes.
0
 
LVL 6

Accepted Solution

by:
Lord_McFly earned 400 total points
ID: 10929357
If the link doesn't actually link to anywhere maybe you could do the following...

<html>
<head>
<title>Example</title>
<script language="Javascript">
<!--
function ChangeImage(ImageName,NewImage)
     {
          eval("document.images."+ImageName+".src=NewImage")
     }
//-->
</script>
</head>
<body>
<%Do while not rs.EOF%>
   <span onMouseOver="ChangeImage('Image','<%=rs("ClassCode")%>.gif')"><%=rs("ClassCode")%></span>
   <%rs.MoveNext
Loop%>
<img name="Image" src="noimage.gif">
</body>
</html>
0
 
LVL 8

Author Comment

by:alexhogan
ID: 10929491
You are absolutely right.  Thanks...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 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