JS script doesn't work for my index.php- works for index.html
My problem: (besides being totally new to javascript-I just want to get this one script to work on my site ) I was able to get this script to workon a simple html page (made in Dreamweaver, saved as html page):
<HTML>
<HEAD>
<SCRIPT>
var which1 = 0;
var rotate = null;
var rotate1 = null;
var imagenames = new Array("one.png","two.png","three.png","four.png","five.png");
var done = imagenames.length;
var images = new Array();
for (var i in imagenames) {
images[i] = new Image();
images[i].src = imagenames[i];
}
function wind() {
clearTimeout(rotate1);
which1 = (which1 + 1)
if (which1 < done)
{document.i2.src = images[which1].src;
rotate1 = setTimeout("wind()", 100);}
else
{which1 = done;}
}
function unwind() {
clearTimeout(rotate1);
which1 = (which1 - 1)
if (which1 >= 0)
{document.i2.src = images[which1].src;
rotate1 = setTimeout("unwind()", 100);}
else
{which1 = 0;}
}
</SCRIPT>
</HEAD>
<BODY>
<A href="#" onClick="return false" onMouseOver="wind()" onMouseOut="unwind()"><IMG name="i2" src="one.png" border=1></A><br>
</BODY>
</HTML> (sorry for posting long code, I don't know what can be left out)
It works, displaying a sequence of five coloured boxes on mouseover, and the reveerse on mouseout. BUT, when I put that code in my index.php(made in dreamweaver, saved as php, and in a 'template' folder with the images and a CSS folder containing the style sheet. The index is mainly nested divs. I will post any code u need, but basically I have tried entereing the 'body' code and image locations many different ways, but it doesn't show up! Does it have anything to do with the way my site is set up (is not one single 'html' page, but dynamic, using a template using index.php, image folder, and CSS sheet? Also has Joomla stuff in the head, and uses many divs. Please help, thanks
Last edited by webwannabee; 10-25-2006 at 05:35 PM..
I see no reason why it won't work on a .php page. Can you post a link to your .php page? Note .php pages won't run locally on your system without a server.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
@Aerospace_Eng- hate to paste a long code like this, but there is no 'link' to it as it's not really on the web, but I am running it on a 'stand-alone-server' (actually JSAS, from Joomla, it is a Joomla CMS template, has index.php, CSS
folder w/style sheets and images folder, all in same 'template-name' folder together. I also put copies of the images loose, in same folder as the index.php. The 'ascroll' div should position the images on topmost layer of site, to be seen...the CSS code:
#ascroll { width: 100%; height: 100%; margin-left: 0px; border:2px; border-color:#66FFFF; background-image: url(../images/one.png);background-repeat:no-repeat; background-position:20px 20px;
<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
// needed to seperate the ISO number from the language file constant _ISO
$iso = explode( '=', _ISO );
// xml prolog
echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
?>
<!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>
<?php mosShowHead(); ?>
<?php
if ( $my->id ) {
initEditor();
}
<SCRIPT language="JavaScript">
var which1 = 0;
var rotate = null;
var rotate1 = null;
var imagenames = new Array("one.png","two.png","three.png","four.png","five.png");
var done = imagenames.length;
var images = new Array();
for (var i in imagenames) {
images[i] = new Image();
images[i].src = imagenames[i];
}
function wind() {
clearTimeout(rotate1);
which1 = (which1 + 1)
if (which1 < done)
{document.i2.src = images[which1].src;
rotate1 = setTimeout("wind()", 100,000);}
else
{which1 = done;}
}
</div><!--end wrap-inner-->
</div> <!--end of wrap-->
</div></div></div></div>
</div></div></div></div>
<!-- -->
</div> <!--box-->
<div id="floor"> </div>
</body>
</html>
Darn! Now I get this error message when viewing the 'site': Parse error: parse error, unexpected '>' in W:\www\locker\templates\tesslocker\index.php on line 16..this is what I have there: <?php
if ( $my->id ) {
initEditor();
}
(lines 13,14,,15,16)
Last edited by webwannabee; 10-25-2006 at 09:23 PM..
I've seen longer but putting your code into php tags and you'll probably see what the problem is.
PHP Code:
<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
// needed to seperate the ISO number from the language file constant _ISO
$iso = explode( '=', _ISO );
// xml prolog
echo '<?xml version="1.0" encoding="'. $iso[1] .'"?' .'>';
?>
<!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>
<?php mosShowHead(); ?>
<?php
if ( $my->id ) {
initEditor();
}
<SCRIPT language="JavaScript">
var which1 = 0;
var rotate = null;
var rotate1 = null;
var imagenames = new Array("one.png","two.png","three.png","four.png","five.png");
var done = imagenames.length;
var images = new Array();
for (var i in imagenames) {
images[i] = new Image();
images[i].src = imagenames[i];
}
function wind() {
clearTimeout(rotate1);
which1 = (which1 + 1)
if (which1 < done)
{document.i2.src = images[which1].src;
rotate1 = setTimeout("wind()", 100,000);}
else
{which1 = done;}
}
K, fixed Aerospace..forgot the ? in the ?> (noob lol). Thanks so much for responding to my long post..site is back, but still no javascript images..just can't figure out what I'm missing, as it worked in my html version of it...it must have something to do with the divs..or how I entered the image location...aaaaaaahhhhhhhhh
Please forgive the image..it shows the files all together in my tempate's folder..and the path to the images (address bar) I also have copies of the images in the 'images' folder. thanks