Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 531
  • Last Modified:

Swapping Images using javascript

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
markej
Asked:
markej
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
markejAuthor Commented:
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now