There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP require & Rollover images conflict


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Arty Owl's Avatar
Computer Specs
Junior Member with 2 posts.
 
Join Date: Aug 2007
Location: England
Experience: Intermediate
16-Aug-2007, 07:02 PM #1
PHP require & Rollover images conflict
Hi, this is my first time using the forums, so my apologies if I don't include something in my explanation I should have.

I'm having a problem when using the PHP require command to call up a navigation menu of rollover images on a separate page. When I call up the menu once on a page there is no problem, but as soon as I include a second instance of the same menu (i.e. one at the top of the page and one at the bottom - to save having to scroll up to move between pages) the rollover images no longer load the second image when the mouse pointer comes into contact with them.

Note: I'm using Dreamweaver 8 mainly in design mode to code all of this for me as I know only a little about the inner workings of HTML and PHP (though enough to get by in most basic situations).

The menu page is in the same folder as the content page I'm loading it into. So I'm using:

Quote:
<?php require("page_menu.htm"); ?>
to call up the menu. This works fine if I include it only once on the page, but if included twice (with no other changes made to the code) it no longer works. I assume it's a problem with the code on the menu page itself - perhapse that part of it comes into conflict with itself if run twice? The code for the menu page is:

Quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

<onLoad="MM_preloadImages('/media/page_numbers/page_numbers_1_on.jpg','/media/page_numbers/page_numbers_2_on.jpg','/media/page_numbers/page_numbers_3_on.jpg','/media/page_numbers/page_numbers_4_on.jpg','/media/page_numbers/page_numbers_5_on.jpg','/media/page_numbers/page_numbers_9_on.jpg','/media/page_numbers/page_numbers_8_on.jpg','/media/page_numbers/page_numbers_7_on.jpg','/media/page_numbers/page_numbers_6_on.jpg','/media/page_numbers/page_numbers_10_on.jpg')">
<div align="center"><img src="/media/page_numbers/page_numbers_title.jpg" width="40" height="25"><a href="sketches01.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 1','','/media/page_numbers/page_numbers_1_on.jpg',1)"><img src="/media/page_numbers/page_numbers_1_off.jpg" alt="Page 1" name="Page 1" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 2','','/media/page_numbers/page_numbers_2_on.jpg',1)"><img src="/media/page_numbers/page_numbers_2_off.jpg" alt="Page 2" name="Page 2" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 3','','/media/page_numbers/page_numbers_3_on.jpg',1)"><img src="/media/page_numbers/page_numbers_3_off.jpg" alt="Page 3" name="Page 3" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 4','','/media/page_numbers/page_numbers_4_on.jpg',1)"><img src="/media/page_numbers/page_numbers_4_off.jpg" alt="Page 4" name="Page 4" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 5','','/media/page_numbers/page_numbers_5_on.jpg',1)"><img src="/media/page_numbers/page_numbers_5_off.jpg" alt="Page 5" name="Page 5" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 6','','/media/page_numbers/page_numbers_6_on.jpg',1)"><img src="/media/page_numbers/page_numbers_6_off.jpg" alt="Page 6" name="Page 6" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 7','','/media/page_numbers/page_numbers_7_on.jpg',1)"><img src="/media/page_numbers/page_numbers_7_off.jpg" alt="Page 7" name="Page 7" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 8','','/media/page_numbers/page_numbers_8_on.jpg',1)"><img src="/media/page_numbers/page_numbers_8_off.jpg" alt="Page 8" name="Page 8" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 9','','/media/page_numbers/page_numbers_9_on.jpg',1)"><img src="/media/page_numbers/page_numbers_9_off.jpg" alt="Page 9" name="Page 9" width="25" height="25" border="0"></a><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Page 10','','/media/page_numbers/page_numbers_10_on.jpg',1)"><img src="/media/page_numbers/page_numbers_10_off.jpg" alt="Page 10" name="Page 10" width="25" height="25" border="0"></a></div>
</html>
I wondered if the Java script was interfering with itself when run twice, but I have a different "site index" menu on the same page which uses identical Java script to run; and since the site index menu continues to work perfectly well with both the single and double inclusions of the navigation menu I presume thats not the problem. My only guess is that there is some conflict I don't know of in the workings of loading the same rollover images twice... but this now a way beyond my knowledge of HTML and PHP code.

I desperately don't want to have to create a separate copy of the navigation menu (e.g. page_menu_top.htm and page_menu_bottom.htm files that are exactly the same in content) as this would completely defeat the point for me of being able to just update one file and not having to remember to update any other instance of the same menu each time.

Any help you can provide me with, to enable to include the menu twice without the rollover images breaking, would be appreciated! Thank you
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,083 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
16-Aug-2007, 08:06 PM #2
You have: <onLoad=".......">

But <onLoad> isn't a HTML tag.

If you want that JS to load when the body of the page loads, try this: <body onload="..."> since <body> is a valid HTML tag.

Also, the structure of the page is all unorganized. You don't define what is the head and what is the body of the document. The only structure tag you have is <html>

This is what a basic pages looks like:

<html>
<head>
<title>Title of the page</title>
(other head stuff here)
</head>
<body>
(everything you want to show up on the page here)
</body>
</html>
__________________
-----------------------------
| 404: Name Not Found |
-----------------------------
PLEASE NOTE: If I happen to help you in a post, or just simply reply to it, doesn't mean I want to be bombarded with PMs. I answer all questions in posts, not in PMs. Thank you, and have a good day.

<?php $h = 'Hello '; $w = 'World'; echo $h.$w; ?>

My Favorite Editors:
Windows: Crimson Editor
Mac: Taco HTML Edit
Linux: gPHPEdit

Last edited by namenotfound : 16-Aug-2007 08:14 PM.
Arty Owl's Avatar
Computer Specs
Junior Member with 2 posts.
 
Join Date: Aug 2007
Location: England
Experience: Intermediate
16-Aug-2007, 08:49 PM #3
Sorry I forgot to mention that part. Yes the <title> <head> and <body> tags are missing as I removed them from the code (bare with me). Whilst seeking help on this rollover image problem from a colleague who knows a bit more about HTML than I do, he mentioned that the problem might be that the browser is trying to interpret several inclusions of <title> <head> and <body> tags as the whole of the code from that menu page will be included when the PHP require command brings it into the main page... if that makes sense.

So I removed the tags, one of which was the "body" from <body onLoad="..."> which I was dubious about for the very reason I didn't know whether it would continue to work like that. However having done so the Java still worked fine (though again only when one copy of the menu was 'required' onto the main page), in fact nothing that was apparent changed for the better or the worse... though if you are saying that <onLoad="..."> on its own shouldn't work, I have no idea why it is continuing to do so.

Just to clarify, the long section of code I quoted in my original post was from the file I'm loading into the main page, and not the main page's code itself. The main page does obviously contain <title> <head> and <body> tags.

*edit*
Ah having said that I suspect the Java still works, not because of some freak of digital nature, but because the same Java code is being used on the main page when the site index menu is loaded through a separate 'require' command elseware on the same page. Presumably it only needs to be present once for the whole lot to work?
Either way the rollover image problem is still present.

*edit again*
Yes, just to confirm, the identical Java script present in the code pulled in from the site index menu file does in fact cause the navigation menu rollovers to work (though again only in the single usage instance).
(I went back and replaced the <head> and <body> tags in their original places and tried removing the Java script entirely from the navigation menu page. After a refresh, the instance of a single usage of the menu continues to work... as again trying to include two copies of the menu doesn't.)
Thanks for the suggestion anyway. Any other ideas?

Last edited by Arty Owl : 16-Aug-2007 09:10 PM.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting 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 Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:47 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.