Page 1 of 1

Include file - linked to other file

Posted: Mon Jan 25, 2010 2:47 am
by bob_marely
I have this problem which I really don't know how to solve… it's really wired and I've tried so many ways then I thought that a different view might reveal something I didn't notice.
So…
I have six divs in my php page with display style = none, except the first div which is visible. I have buttons which their onclick event change the display of the divs, i.e. make one div visible and the others invisible. It works like magic except for the second div where it also includes the php file from the third div.
Of course that snap code is always better than words:
<div id="1" style="width: 950px; display: block">
<?php include('file1.php'); ?>
</div>

<div id="2" style="width: 950px; display: none">
<?php include('file2.php'); ?>
</div>

<div id="3" style="width: 950px; display: none">
<?php include('file3.php'); ?>
</div>
<div id="4" style="width: 950px; display: block">
<?php include('file4.php'); ?>
</div>

<div id="5" style="width: 950px; display: none">
<?php include('file5.php'); ?>
</div>

<div id="6" style="width: 950px; display: none">
<?php include('file6.php'); ?>
</div>


And this is the code for the onclick event:
<a href="javascript:void(0);" onclick="includefile(1); return false;" > <img name="child" border="0" src="images/child.gif" width="180" height="30" /></a>

There are six buttons like this one with different gifs and each button include different file.


I tried many things – change the order, replace the included files, create new files, etc. but the bug still remains: always when changing the second div visibility it includes also the file in the div below it (I checked the display style of the third div and it remains none – it's just the third file is included under the second div).

Sorry for the long story – I wanted to be clear and I believe that knowing all the details may help for having some ideas.

Thank you for any advice!!

Re: Include file - linked to other file

Posted: Mon Jan 25, 2010 2:57 am
by amargharat
use following javascript code

Code: Select all

function includefile(id)
{
     //hide all divs
     for(i=1;i<=6;i++)
     {
          document.getElementById(i).style.display='none';
     }
     
     //display div with requetsed id
     document.getElementById(id).style.display='block';
}

Re: Include file - linked to other file

Posted: Mon Jan 25, 2010 4:25 am
by bob_marely
Thanks! but I use a similar code:

Code: Select all

function includefile(fname) {
    
    for (i=1;i<=11;i++) {
        if ( fname == i) {
            document.getElementById(fname).style.display='block';
        }
        else {
            document.getElementById(i).style.display='none';
        }
    }
}
As I mentioned it works good for all divs - except from div id=2 where it includes also the file which is included under div id =3...

My question is if anyone has an idea why it happens????

Re: Include file - linked to other file

Posted: Mon Jan 25, 2010 9:34 am
by AbraCadaver
Either file2.php is actually including file3.php, or file2.php has some HTML that is breaking the HTML in the main page and so causing both divs to be displayed. You need to check file2.php and the view source of the resultant main page.

Re: Include file - linked to other file

Posted: Mon Jan 25, 2010 9:18 pm
by bob_marely
Brilliant!

I used the w3 validator and indeed there was some missing tag...

Thanks alot!