/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] HTML DOCTYPE breaks javascript only in FireFox

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”> [/code]

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;
}
[/CODE]

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>[/code]

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@kingafrojoeauthorDec 05.2009 — Hi i for got to include the Demo pages.

no doctype:

http://joemayhew.co.uk/test/image.html

with doctype:

http://joemayhew.co.uk/test/image-doctype.html

thanks again.
Copy linkTweet thisAlerts:
@FangDec 05.2009 — Use valid referencing:[COLOR="Navy"]document[/COLOR].mainimage.src
Copy linkTweet thisAlerts:
@kingafrojoeauthorDec 05.2009 — Works Perfectly, thanks a lot!!!!
×

Success!

Help @kingafrojoe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...