Solved

Swapping Images using javascript

Posted on 2011-03-08
2
522 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

759 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

19 Experts available now in Live!

Get 1:1 Help Now