Solved

Swapping Images using javascript

Posted on 2011-03-08
2
525 Views
Last Modified: 2013-12-14
I want to create an image similar to this : http://www.returnloads.net/loads.asp?area=12

Loading the images dynamically from a database, i.e. 1 main image and then depending on the area the mouse rolls over in the map overlay one of four images would be loaded to replace the original one. again when the mouse rolls off the image the original image is returned.  I've tried using the attached codebehind  BUT it's not working because of the syntax problems associated with the javascript and the ' quotes.

        Image7.Attributes.Add("usemap", "#map1")
        Dim Mainimg As String = "main.jpg"
        Dim img1 As String = "graphics/a.gif"
        Dim img2 As String = "graphics/b.jpg"
        Dim img3 As String = "graphics/c.gif"
        Dim img4 As String = "graphics/d.gif"

        Litadvert.Text &= "<map name='Map1' id='Map1'>"
        Litadvert.Text &= "<area shape='rect' coords='2,1,123,108' href='' onmouseover='javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & img1 & "'' onmouseout='javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & mainimg &"'"/>"
        Litadvert.Text &= "<area shape='rect' coords='134,1,259,108' href='' onmouseover=javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & img2 & "' onmouseout='MM_swapImgRestore()'/>"
        Litadvert.Text &= "<area shape='rect' coords='269,1,394,108' href='' onmouseover='javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & img3 & "'' onmouseout='javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & mainimg &"'"/>"
        Litadvert.Text &= "<area shape='rect' coords='405,1,525,108' href='' onmouseover='javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & img4 & "'' onmouseout='javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & mainimg &"'"/>"
        Litadvert.Text &= "</map>"

Where mainimg and img1 etc would in reality be loaded from a database,

This is giving syntax errors and the mouseover evnt isn't working.

Can anyone suggest a way of fixing this or an alternative to do the same thing?
0
Comment
Question by:markej
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35069763
It looks like it is just a syntactic issue because of the quotes. Try it as:
 Litadvert.Text &= "<area shape=""rect"" coords=""2,1,123,108"" href="""" onmouseover=""javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & img1 & "'"" onmouseout=""javascript:ctl00_CPHReturnLoadsAdvert_Image7.src='" & mainimg & "'"" />"

Open in new window

You might need to stick a few spaces in there to check for yourself which are quotes and which are apostrophes :)
0
 

Author Closing Comment

by:markej
ID: 35070243
Great it works, thanks for the help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

820 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