HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
A little question about a simple switch statement
Post new topic   Reply to topic    HTML Help Forum Index -> PHP
View previous topic :: View next topic  
Author Message
HaLo2FrEeEk



Joined: 03 Dec 2006
Posts: 2

PostPosted: Sun Dec 03, 2006 6:37 pm     A little question about a simple switch statement Reply with quote

I am trying to write a simple switch statement that will call up a javascript located on the page, to load a different page into an iframe depending on a variable in the URL, The code I am using is:

Code:

<?php
$view="home";
switch ($_GET["view"]) {
case "home":
  echo "<script type=\"javascript\"><!--";
  echo "fasttravel('pages/home.html','Home');";
  echo "// --></script>";
  break;
case "roster":
  echo "<script type=\"text/javascript\"><!--";
  echo "fasttravel('pages/roster.html','Roster');";
  echo "// --></script>";
  break;
  }
?>


Where fasttravel() is the javascript I want to call up, this javascript function is very simple:

Code:

function fasttravel(url,title){
maincontent.location=url;
document.title="Clan Infectionist :: "+title;
}


Something is wrong though and I can't get it to go to the roster, this is only a test of the code, there are 6 different pages I want it to be able to load: home, roster, affiliates, projects, movies, and music, right now, to get to these pages, people have to go to the main page, then click the respective link to load the, for example, roster, into the iframe, I want them to be able to type: http://claninfectionist.com/?view=roster and it will take them there automatically using the javascript, but for whatever reason, its not reading the variable from the url, it always defaults back to home if the ?view= is in the url, what can I do?
Thanks in advance.

~HaLo2FrEeEk
degsy



Joined: 23 Feb 2005
Posts: 2440
Location: North East, UK

PostPosted: Fri Dec 08, 2006 6:51 am     Reply with quote

Why are you using javascript at all when you can use PHP to set the src of the iframe?


You problem is because you are calling the script before the iframe has been created.

Change your script to ouput an onload event instead.
HaLo2FrEeEk



Joined: 03 Dec 2006
Posts: 2

PostPosted: Sun Dec 10, 2006 11:23 pm     Reply with quote

I could use all php, but my knowledge of php, and thusly, creativity with it, is about this: |_|, yeah, anywho, I figured out how to do it with javascript, just did a substr with a switch statement to find anything after the view=, so basically, someone can go to http://claninfectionist.com/?view=roster and it will take them to the frontpage, but will load the roster in the frame, its crude, but it works, for now.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> PHP All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial