Solved

Image show on rollover

Posted on 2004-04-23
7
1,197 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now