www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] HTML DOCTYPE breaks javascript only in FireFox

  1. #1
    Join Date
    Dec 2009
    Location
    UK
    Posts
    30

    resolved [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:
    HTML Code:
    <!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:
    HTML Code:
    <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

  2. #2
    Join Date
    Dec 2009
    Location
    UK
    Posts
    30
    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.

  3. #3
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Use valid referencing:
    Code:
    document.mainimage.src

  4. #4
    Join Date
    Dec 2009
    Location
    UK
    Posts
    30
    Works Perfectly, thanks a lot!!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles