Solved

Swapping Images using javascript

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

815 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

12 Experts available now in Live!

Get 1:1 Help Now