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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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];
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.