Javascript created with php doesn't work.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Javascript created with php doesn't work.

Post by Stephen Bungert »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n";
        echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<script language=\"javascript\" type=\"text/javascript\">\n";
		echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<!-- /\n";
		echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar currentNumber	= 0;\n";
		echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar maxNumber		= " . count($dataNew) . ";\n\n";
		
		for ($index = 0; $index < count($dataLinksNew); $index ++)
		{
			echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar spiel" . $index . "	= \"images/sections/termine_" . $dataLinksNew[$index] . "_large.jpg\";\n";
		}
		
		echo "\n";
		
		for ($index = 0; $index < count($dataLinksNew); $index ++)
		{
			echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar titleText" . $index . "	= \"" . $dataNew[$index] . "\";\n";
		}
		
		echo "\n";
		
		for ($index = 0; $index < count($dataLinksNew); $index ++)
		{
			echo "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar link" . $index . "	= \"javascript:openTermineItem('" . $dataLinksNew[$index] . "', 'home')\";\n";
		}
?>
																
																function startNowPlaying()
																{
																	alert ("In");
																	setInterval('changeSpiel();', 4000);
																}
																
																function changeSpiel()
																{
																	document.getElementById("spielImage").src		= eval ("spiel" + currentNumber);	// Change image
																	document.getElementById("mainTitle").innerHTML	= eval ("titleText" + currentNumber);
																	document.getElementById("spielImageLink").href	= eval ("link" + currentNumber);
																	document.getElementById("infoLink").href		= eval ("link" + currentNumber);
																	
																	if (currentNumber >= maxNumber)
																	{
																		currentNumber = 0;
																	}
																	else
																	{
																		currentNumber ++;
																	}
																}
	 															/ -->
 															</script>
Above is part of my code.

Code: Select all

<script language="JavaScript" type="text/javascript">
																<!-- /
																var currentNumber	= 0;
																var maxNumber		= 12;

																var spiel0	= "images/sections/termine_Title1_large.jpg";
																var spiel1	= "images/sections/termine_Title2_large.jpg";
																var spiel2	= "images/sections/termine_Title3_large.jpg";
																var spiel3	= "images/sections/termine_Title4_large.jpg";
																var spiel4	= "images/sections/termine_Title5_large.jpg";
																var spiel5	= "images/sections/termine_Title6_large.jpg";
																var spiel6	= "images/sections/termine_Title7_large.jpg";
																var spiel7	= "images/sections/termine_Title8_large.jpg";
																var spiel8	= "images/sections/termine_Title9_net_large.jpg";
																var spiel9	= "images/sections/termine_Title10_large.jpg";
																var spiel10	= "images/sections/termine_Title11_large.jpg";
																var spiel11	= "images/sections/termine_Title12_large.jpg";

																var titleText0	= "Title1";
																var titleText1	= "Title2";
																var titleText2	= "Title3";
																var titleText3	= "Title4";
																var titleText4	= "Title5";
																var titleText5	= "Title6";
																var titleText6	= "Title7";
																var titleText7	= "Title8";
																var titleText8	= "Title9";
																var titleText9	= "Title10";
																var titleText10	= "Title11";
																var titleText11	= "Title12";

																var link0	= "javascript:openTermineItem('Title1', 'home')";
																var link1	= "javascript:openTermineItem('Title2', 'home')";
																var link2	= "javascript:openTermineItem('Title3', 'home')";
																var link3	= "javascript:openTermineItem('Title4', 'home')";
																var link4	= "javascript:openTermineItem('Title5', 'home')";
																var link5	= "javascript:openTermineItem('Title6', 'home')";
																var link6	= "javascript:openTermineItem('Title7', 'home')";
																var link7	= "javascript:openTermineItem('Title8', 'home')";
																var link8	= "javascript:openTermineItem('Title9', 'home')";
																var link9	= "javascript:openTermineItem('Title10', 'home')";
																var link10	= "javascript:openTermineItem('Title11', 'home')";
																var link11	= "javascript:openTermineItem('Title12', 'home')";
																
																function startNowPlaying()
																{
																	alert ("In");
																	setInterval('changeSpiel();', 4000);
																}
																
																function changeSpiel()
																{
																	document.getElementById("spielImage").src		= eval ("spiel" + currentNumber);	// Change image
																	document.getElementById("mainTitle").innerHTML	= eval ("titleText" + currentNumber);
																	document.getElementById("spielImageLink").href	= eval ("link" + currentNumber);
																	document.getElementById("infoLink").href		= eval ("link" + currentNumber);
																	
																	if (currentNumber >= maxNumber)
																	{
																		currentNumber = 0;
																	}
																	else
																	{
																		currentNumber ++;
																	}
																}
	 															/ -->
 															</script>
Above is the from the source html that is generated by the php. In the body tag is an onload attribute which calls startNowPlaying(), but all browser's I've tested say it doesn't exist. But it's in the html that is generated.

Why doesn't it exist?


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

It all worked when it was linked as javascript file in the head. To cut down on updates I'm trying to automate part of the site. It all works but the images and text doesn't change because the function that starts the time that makes the change doesn't exist although it's in the code.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

got a live version we can look at?
Stephen Bungert
Forum Commoner
Posts: 25
Joined: Sat Feb 25, 2006 3:22 am

Post by Stephen Bungert »

sorry about the wrong code tags!

Please look at http://www.alicehoffmann.de

The first page has a Now Playing kind of thing on the right side. It SHOULD cycle through the plays in the Calender (Termine) but it doesn't.

The JavaScript is now inserted by PHP and builds a list of images/text to display based on the info in the Termine data file.

Previously I had to update the javascript by hand, so now I'm trying to automate it and it doesn't work. Though the only difference was that before the js was linked to in the head section.

Please view the source of the page, you can see that the javascript is there but according to firefox and opera the startNowPlaying() function doesn't exist.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't see any Javascript on "Termine" .. only references to some external scripts.
Post Reply