|
|
#1 |
|
Silver Member
![]() |
First of all, I'm sorry for cluttering up the forums with all these similar threads, but I keep running into new snags.
What I have here is a main <div> with nav buttons above. When I click the buttons (<td> with onclick function), I want to include() the respective php file into that div. I've tried all sorts of scripting, but I can't find a solution. I figured the only way to change the contents of the div is to have a function (called from the nav button) that passes a keyword into a switch that will determine the code to write, which I would then insert into the div using the innerHTML attribute. The problem is that the php statements are parsed before the script is run, so the file data is written out onto the page source. However, it's not even writing that to the div. I'm sure that might be quite confusing, so please ask for clarification where necessary. Last edited by AusQB; 03-12-2009 at 09:54 AM. |
|
|
|
|
|
#2 |
|
Silver Member
![]() Join Date: Nov 2008
Location: Minnesota
Posts: 224
|
Code:
<?php
if (isset($_REQUEST['tab'])) {
$tab = $_REQUEST['tab'];}
else {$tab = 1;}
?>
<!DOCTYPE...
Code:
<?php
switch ($tab) {
case 1:
?>
<div id="navbar">
<b>Tab 1</b>
<a href="index.php?tab=2">Tab 2</a>
<a href="index.php?tab=3">Tab 3</a>
</div>
<?php include("page1.php"); ?>
<?php
break;
case 2:
?>
<div id="navbar">
<a href="index.php?tab=1">Tab 1</a>
<b>Tab 2</b>
<a href="index.php?tab=3">Tab 3</a>
</div>
<?php include("page2.php"); ?>
<?php
break;
case 3:
?>
<div id="navbar">
<a href="index.php?tab=1">Tab 1</a>
<a href="index.php?tab=2">Tab 2</a>
<b>Tab 3</b>
</div>
<?php include("page3.php"); ?>
<?php
break;}
?>
__________________
http://www.htmlswag.com |
|
|
|
|
|
#3 |
|
Silver Member
![]() |
Thanks, I'll try that.
Just for clarification, is the second batch of code meant to encapsulate the nav bar and the main div area? Also, why is the first batch of code before the document declaration? EDIT: That's exactly what I was looking for, thanks. One thing though, how can I change what is initially displayed? I actually don't need it for changing pages now, but rather for navigating to different levels of a single page. So once I click on one of the links in the "navbar", I want the content of the div to be replaced. Last edited by AusQB; 03-12-2009 at 10:16 AM. |
|
|
|
|
|
#4 | |
|
Silver Member
![]() Join Date: Nov 2008
Location: Minnesota
Posts: 224
|
Quote:
i.e. you can have three divs that are essentially the same and it'll swap between them just as you wanted. Also it doesn't really matter what you put inside the code but anything outside will remain the same. Code:
<div id="navbar">
<a href="index.php?tab=1">Tab 2</a>
<a href="index.php?tab=2">Tab 2</a>
<a href="index.php?tab=3">Tab 3</a>
</div>
<?php
switch ($tab) {
case 1:
?>
<div>something</div>
<?php
break;
...
__________________
http://www.htmlswag.com |
|
|
|
|
|
|
#5 |
|
Silver Member
![]() |
Ah I understand now, thanks. I was just trying to get my head around the tab variable.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|