I am realtively new to java script, so my apologise.
I am trying to create an image map of regional map. i have created the image map and would now like to have the areas contained in it highlighted with a mouse over. i have come to the conclusion that i need to do an image swap for each area?
i have used the code supplied in the book "web design in a nutshell"
but still cant get it to go, keeps coming up with the same error.
document.image is null or not an object.
anyone out there able to help? please.
code as below:
<script language = "javascript">
<!--
if (document.images) {
//"On" images
img1on = new Image();
img1on.src = "mapHawkesbay.jpg";
//"Off" images
img1off = new Image();
img1off.src = "imagemap.jpg";
}
function imgOn(imgName) {
if (document.images) {
document.images[imgName].src = eval(imgName + "on.src");
}
}
function imgOff(imgName) {
if (document.images) {
document.images[imgName].src = eval(imgName + "off.src");
}
}
//-->
i think i understand what you are saying, however i need to change several images in the same map, how do i do that??? do i have to give each area and id?
any help gratefully received?
<script language = "javascript">
<!--
if (document.images) {
//"On" images
img1on = new Image();
img1on.src = "mapHawkesbay.jpg";
img2on = new Image();
img2on.src = "mapwairaiarapa.jpg";
img3on = new Image();
img3on.src = "mapGisborne.jpg";
//"Off" images
img1off = new Image();
img1off.src = "imagemap.jpg";
}
function imgOn(imgName) {
if (document.images) {
document.images[imgName].src = eval(imgName + "on.src");
}
}
function imgOff(imgName) {
if (document.images) {
document.images[imgName].src = eval(imgName + "off.src");
}
}
//-->
You also need to define the various images on the page that the code is updating (you didn't include that code in the HTML you posted as there are no <img> tags specified in your post and they are what the code will update). I assume that the error you are asking about is because you didn't include the images in your page.