Results 1 to 2 of 2

Thread: Element referenced by ID/NAME in global context. problem

  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Element referenced by ID/NAME in global context. problem

    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

    Code:
    <!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>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!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>
    Last edited by jscheuer1; 07-03-2010 at 06:22 PM. Reason: validate code
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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