PDA

View Full Version : Element referenced by ID/NAME in global context. problem



yanthegreat15
07-03-2010, 05:09 PM
Hi,

The following code displays simultaneously a text message and makes an image move around. However, the first message (quotations[0]) doesn't appear when the corresponding image moves (but the following text messages (1,2, and so on) appear correctly). And under Firefox, I receive this notice:

Élément référencé par son ID/NAME dans le contexte global. Utilisez la propriété standard du W3C « document.getElementById() » à la place.

Someone could help me with this issue?

Thanks in advance


<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Demo</title>
<script language="JavaScript">

var quotations = new Array()
quotations[0]= "Message 0"
quotations[1]= "Message 1"
quotations[2]= "Message 2"

function cpSequencer(n)
{
switch(n)
{
case 0:
moveObjLeft(JS, 500, 400, 4); //ID-PX départ-Px fin-Vitesse
document.getElementById('quotation').innerHTML=quotations[0]
break;
case 1:
moveObjLeft(JS, 400, 250, 4); //ID-PX départ-Px fin-Vitesse
document.getElementById('quotation').innerHTML=quotations[1]
break;
case 2:
moveObjLeft(JS, 250, 50, 4); //ID-PX départ-Px fin-Vitesse
document.getElementById('quotation').innerHTML=quotations[2]
break;

default:
break;
}
}

i=0;
function moveObjRight(obj, START, END, SPEED) {
obj.style.left=START;
START+=SPEED;
if(START<END) window.setTimeout("moveObjRight(" +obj.id+", " +START+ ", " +END+ ", " +SPEED+ ");", 0);
else {
i++;
setTimeout("cpSequencer(i);",2000)

}
}
function moveObjLeft(obj, START, END, SPEED) {
obj.style.left=START;
START-=SPEED;
if(START>END) window.setTimeout("moveObjLeft(" +obj.id+", " +START+ ", " +END+ ", " +SPEED+ ");", 0);
else {
i++;
setTimeout("cpSequencer(i);",2000)
}
}

</script>
</head>

<body>
<table BACKGROUND="bg.png" width="1730" height="736" border="1"><tr><td>
&nbsp;
</td></tr></table>

<p><img id="JS" style="z-index: 0; left: -100px; position: absolute; top: 12px"
height=730 width=3 align=baseline border=0 hspace=0 src="image.jpg"></p>

<script language="JavaScript">
cpSequencer(0);
</script>
<div id="quotation"></div>
</body>
</html>

jscheuer1
07-03-2010, 06:03 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Demo</title>
<script type="text/javascript">

var quotations = new Array()
quotations[0]= "Message 0"
quotations[1]= "Message 1"
quotations[2]= "Message 2"

function cpSequencer(n)
{
var JS = document.getElementById('JS') ;
switch(n)
{
case 0:
moveObjLeft(JS, 500, 400, 4); //ID-PX départ-Px fin-Vitesse
document.getElementById('quotation').innerHTML=quotations[0]
break;
case 1:
moveObjLeft(JS, 400, 250, 4); //ID-PX départ-Px fin-Vitesse
document.getElementById('quotation').innerHTML=quotations[1]
break;
case 2:
moveObjLeft(JS, 250, 50, 4); //ID-PX départ-Px fin-Vitesse
document.getElementById('quotation').innerHTML=quotations[2]
break;

default:
break;
}
}

i=0;
function moveObjRight(obj, START, END, SPEED) {
obj.style.left=START + 'px';
START+=SPEED;
if(START<END) setTimeout(function(){moveObjRight(obj, START, END, SPEED);}, 0);
else {
i++;
setTimeout("cpSequencer(i);",2000)

}
}
function moveObjLeft(obj, START, END, SPEED) {
obj.style.left=START + 'px';
START-=SPEED;
if(START>END) setTimeout(function(){moveObjLeft(obj, START, END, SPEED);}, 0);
else {
i++;
setTimeout("cpSequencer(i);",2000)
}
}

</script>
</head>

<body>
<table style="background-image: bg.png; width: 1730px; height: 736px;" border="1"><tr><td>
&nbsp;
</td></tr></table>

<p><img id="JS" style="z-index: 0; left: -100px; position: absolute; top: 12px"
height=730 width=3 alt="" src="image.jpg"></p>

<div id="quotation"></div>
<script type="text/javascript">
cpSequencer(0);
</script>
</body>
</html>