Jump to content

[SOLVED] Adding doctype xhtml, javascript not working


gli

Recommended Posts

Why my javascript code is not working in Mozilla Firefox ( not in IE) when i add doctype 'xhtml' to my code?

Thanks.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" rev="stylesheet" href="styles.css" />
<script type="text/javascript" src="skript.js"></script>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:205px;
top:16px;
width:200px;
height:100px;
z-index:1;
color: red;
}
-->
</style>
</head>
<body onload="goRightTime(), fadeOutTime()">
<div id="apDiv1"><a href='one.html'>this is one</a></div>
<a id="linkleft" href="#" onclick="goLeft(), stopInterval(), fadeout(), fadeout2()"></a>
<div id="boxLeft"><img height="80" width="100" id="imgLeft" src="images/0.gif" alt="imgleft"></img></div>
<div id="boxMid"><img height="100" width="200" id="imgMid" src="images/one.gif" alt="imgmid"></img></div>
<div id="boxRight"><img height="80" width="100" id="imgRight" src="images/two.gif" alt="imgright"></img></div>
<a id="linkright" href="#" onclick="goRight(), stopInterval()"></a>

</body>
</html>

Without at least posting your javascript, and preferably posting a link, it's almost impossible to say what is wrong.

 

Try downloading firefox and the firebug plugin. The firebug plugin has a great javascript error console that will tell you what the errors are in your script so that you can fix them.

Ok Thanks! 

But fireBug says:  "Error: imgLeft is not defined"

 

 

var myPix = new Array("images/0.gif","images/one.png","images/two.gif","images/three.gif","images/four.gif");

function goRight()
{
  myPix.push(myPix.shift());
imgLeft.src = myPix[0];
imgMid.src = myPix[1] 
imgRight.src = myPix[2];
}

you can try document.boxLeft.imgLeft.src

 

This javascript is dependent on the name attribute, not the id attribute. It's also older javascript and doesn't follow the DOM model, so it's kind of outdated. Your second one would work though.

 

That being said, this code will target the image directly:

 

document.getElementById("imgLeft").src = "path/to/source"

 

repeat for imgMid and imgRight

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.