...

View Full Version : JS script doesn't work for my index.php- works for index.html



webwannabee
10-25-2006, 06:25 PM
My problem: (besides being totally new to javascript-I just want to get this one script to work on my site:rolleyes: ) 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

_Aerospace_Eng_
10-25-2006, 07:30 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.

webwannabee
10-25-2006, 10:10 PM
@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;}
}

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>
<div align="center">
<div id="header">
<div align="center">
<div id="inner-header">
<?php echo $mosConfig_sitename; ?> <?php mospathway() ?>
</div>
</div>
</div>
</div> <!-- the HEADER of course-->

<div id="sidebar">
<div class="side_inside">
<?php mosLoadModules('left',-3);?>
</div></div> <!--MAINMENU on the wall-->

<div id="box">
<div id="wrap">
<div id="wrap-inner">
<!--- box border -->
<div id="lb">
<div id="rb">
<div id="bb"><div id="blc"><div id="brc">
<div id="tb"><div id="tlc"><div id="trc">
<!-- --> <!--box border, locker edges-->

<div id="main-body">
<div id="content">
<div class="content_inside">
<div id="shelf_1">
<div id="shelf_2">
<div id="top_shelf">
<div id="ascroll" IMG src="one.png" border=0 />
<A href="#" onclick="return false" onmouseover="wind()" onmouseout="unwind()"><IMG name="i2" src="one.png" border=0></A><br>
</div>
</div>
</div>
</div>

</div></div>
<!--end content/inside-->

<div id="sidebar-2">
<div class="side2_inside">
<?php mosLoadModules('right',-3);?>
</div></div><!--end sidebar-2, inside-->

</div><!--end main body-->

<div id="footer">
<?php include_once( $mosConfig_absolute_path .'/includes/footer.php');?>
</div>

</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)

_Aerospace_Eng_
10-25-2006, 10:13 PM
I've seen longer but putting your code into php tags and you'll probably see what the problem is.

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

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>
<div align="center">
<div id="header">
<div align="center">
<div id="inner-header">
<?php echo $mosConfig_sitename; ?> <?php mospathway() ?>
</div>
</div>
</div>
</div> <!-- the HEADER of course-->

<div id="sidebar">
<div class="side_inside">
<?php mosLoadModules('left',-3);?>
</div></div> <!--MAINMENU on the wall-->

<div id="box">
<div id="wrap">
<div id="wrap-inner">
<!--- box border -->
<div id="lb">
<div id="rb">
<div id="bb"><div id="blc"><div id="brc">
<div id="tb"><div id="tlc"><div id="trc">
<!-- --> <!--box border, locker edges-->

<div id="main-body">
<div id="content">
<div class="content_inside">
<div id="shelf_1">
<div id="shelf_2">
<div id="top_shelf">
<div id="ascroll" IMG src="one.png" border=0 />
<A href="#" onclick="return false" onmouseover="wind()" onmouseout="unwind()"><IMG name="i2" src="one.png" border=0></A><br>
</div>
</div>
</div>
</div>

</div></div>
<!--end content/inside-->

<div id="sidebar-2">
<div class="side2_inside">
<?php mosLoadModules('right',-3);?>
</div></div><!--end sidebar-2, inside-->

</div><!--end main body-->

<div id="footer">
<?php include_once( $mosConfig_absolute_path .'/includes/footer.php');?>
</div>

</div><!--end wrap-inner-->
</div> <!--end of wrap-->

</div></div></div></div>
</div></div></div></div>
<!-- -->
</div> <!--box-->
<div id="floor"> </div>
</body>
</html>
You don't actually ever close your opening php tag

<?php
if ( $my->id ) {
initEditor();
}
before you start your JS. See it helps to post all of your code in the beginning. It saves time for you and the people that help you.

webwannabee
10-25-2006, 11:43 PM
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

_Aerospace_Eng_
10-25-2006, 11:46 PM
Is the index.php file in the same directory as the image files?

webwannabee
10-26-2006, 12:15 AM
[img=http://img128.imageshack.us/img128/2145/screen1fh5.th.png] (http://img128.imageshack.us/my.php?image=screen1fh5.png)

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum