Hi community
i am trying to teach myself JavaScript and I have come across this error several times and I have no idea why? basically this script works fine in IE and Chrome but when it is accessed in Firefox the script breaks I found that if the html doctype is removed the script works fine. any advice on how to work around this and avoid this problem in the future?
Doctype:
[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
Script:
[CODE]//Original script from: http://javascript.internet.com/miscellaneous/image-viewer.html
window.onload = function ()
{
var imagesA = [‘noimage.jpg’,’TownArtPlaceHolder.jpg’,’accommodation_4.jpg’,’accommodation_7.jpg’];
mainimage.src = “noimage.jpg”;
}
<!– Begin
function changeImage(filename)
{
mainimage.src = filename;
}
HTML:
[code=html]<p>
<a href=”javascript:changeImage(‘noimage.jpg’)”>Image 1</a>
<a href=”javascript:changeImage(‘TownArtPlaceHolder.jpg’)”>Image 2</a>
<a href=”javascript:changeImage(‘accommodation_4.jpg’)”>Image 3</a>
<a href=”javascript:changeImage(‘accommodation_7.jpg’)”>Image 4</a>
</p>
<p>
<img name=”mainimage” src=”noimage.jpg”></p>
Thanks