Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Image show on rollover

Posted on 2004-04-23
7
Medium Priority
?
1,206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1600 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

721 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