Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Problem with a PHP/JavaScript include file....

Problem with a PHP/JavaScript include file....
Thread Tools
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status: Offline
Reply With Quote
Apr 24, 2003, 02:33 PM
 
I'm trying to use a PHP script to include in all my pages via:

[php]<script src="../scripts/rollover.php?sub=1" type="text/javascript" language="Javascript"></SCRIPT>[/php]

The reason I'm doing this is so I can use one global rollover script that can be included with simple adjustment to the X in the "sub=X" field.

Now, I'm having problems getting the script to work. It works fine when a file is sitting in the root of my server (sub=0) but when I try to reference from any folders below the site (sub=1, etc.) the script doesn't seem to work.

Here is the code:
[php]
<?
for ($i=1; $i<=${"sub"}; $i=$i+1)
{

$Location=$Location+"../";

}

?>

<!--
var roll = 0;
if (navigator.appName == "Netscape" && parseFloat(navigator.appVersion) >= 3.05){roll=1;}
else if (navigator.appName == "Microsoft Internet Explorer" && parseFloat(navigator.appVersion) >= 3.02){roll=1;}

if ((document.images) && (roll == 1)) {

//preload main nav out images
whoOut = new Image();
whoOut.src = "<? echo $Location; ?>images/nav/main_who.gif";
whatOut = new Image();
whatOut.src = "<? echo $Location; ?>images/nav/main_what.gif";
newsOut = new Image();
newsOut.src = "<? echo $Location; ?>images/nav/main_about.gif";
contactOut = new Image();
contactOut.src = "<? echo $Location; ?>images/nav/main_contact.gif";
workOut = new Image();
workOut.src = "<? echo $Location; ?>images/nav/main_working.gif";
homeOut = new Image();
homeOut.src = "<? echo $Location; ?>images/nav/main_home.gif";
arrowOut = new Image();
arrowOut.src = "<? echo $Location; ?>images/nav/arrow.gif";


//preload main nav over images
whoOver = new Image();
whoOver.src = "<? echo $Location; ?>images/nav/main_who_o.gif";
whatOver = new Image();
whatOver.src = "<? echo $Location; ?>images/nav/main_what_o.gif";
newsOver = new Image();
newsOver.src = "<? echo $Location; ?>images/nav/main_about_o.gif";
contactOver = new Image();
contactOver.src = "<? echo $Location; ?>images/nav/main_contact_o.gif";
workOver = new Image();
workOver.src = "<? echo $Location; ?>images/nav/main_working_o.gif";
homeOver = new Image();
homeOver.src = "<? echo $Location; ?>images/nav/main_home_o.gif";
arrowOver = new Image();
arrowOver.src = "<? echo $Location; ?>images/nav/arrow_o.gif";

}



//Begin Function for Rollover On State
function imgOn(imgName) {
if ((document.images) && (roll==1)) {
document[imgName].src = eval(imgName + "Over.src");
}
}
//End Function for Rollover On State

//Begin Function for Rollover Off State
function imgOff(imgName) {
if ((document.images) && (roll==1)) {
document[imgName].src = eval(imgName + "Out.src");
}
}
//End Function for Rollover Off State

//Begin Function for Rollover On State
function terOn(imgName) {
if ((document.images) && (roll==1)) {
document[imgName].src = arrowOver.src;
}
}
//End Function for Rollover On State

//Begin Function for Rollover Off State
function terOff(imgName) {
if ((document.images) && (roll==1)) {
document[imgName].src = arrowOut.src;
}
}
//End Function for Rollover Off State

// Begin Function for Opening New Window with Event-Specified Parameters
function newWindow(filePath,winName,winProperties){
window.open(filePath,winName,winProperties);
}
// End Function for Opening New Window with Event-Specified Parameters
//-->
[/php]

If anybody could help or could suggest a different forum where I could find help I'd appreciate it, I think at this point I've been staring at it for too long to pick up the problem.

Sorry I had to use the "php" vBcode b/c the "code" tag didn't seem to work
(Last edited by shadybirdstan; Apr 24, 2003 at 02:40 PM. )
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Apr 24, 2003, 07:03 PM
 
Originally posted by shadybirdstan:
[php]
<?
for ($i=1; $i<=${"sub"}; $i=$i+1)
{

$Location=$Location+"../";

}

?>
[/php]
Try:

$Location .= "../"

I don't think an addition symbol works the same in PHP as it does in Javascript for string concatenation.
Computer thez nohhh...
     
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status: Offline
Reply With Quote
Apr 25, 2003, 09:04 AM
 
Originally posted by Simon Mundy:
Try:

$Location .= "../"

I don't think an addition symbol works the same in PHP as it does in Javascript for string concatenation.
...it doesn't. it's also good programming practice to initialize $Location to the null string prior to doing a .= though php does that for you automatically
     
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status: Offline
Reply With Quote
Apr 25, 2003, 09:06 AM
 
Originally posted by Simon Mundy:
Try:

$Location .= "../"

I don't think an addition symbol works the same in PHP as it does in Javascript for string concatenation.
Heh, that was it. I figured it was something simple that I was just missing after staring at the code.

Thanks for the help .
     
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status: Offline
Reply With Quote
Apr 25, 2003, 09:09 AM
 
also, if your image folder is located at the root of your site, you could bypass the whole script thing by using your image refs like "/images/myImage.jpg" instead of "images/myImage.jpg"...

less overhead.
     
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status: Offline
Reply With Quote
Apr 25, 2003, 02:47 PM
 
Originally posted by ameat:
also, if your image folder is located at the root of your site, you could bypass the whole script thing by using your image refs like "/images/myImage.jpg" instead of "images/myImage.jpg"...

less overhead.
True, good point .
     
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status: Offline
Reply With Quote
Apr 25, 2003, 02:48 PM
 
Originally posted by shadybirdstan:
True, good point .
...but not as fun.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:26 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2