Page 1 of 1

Set flag in menu to include iframe in other page

Posted: Mon May 08, 2006 6:04 am
by michaelm
I need some advice and expect that the solution is rather simple; though I’m stuck on this for several days already (since I’m still learning PHP).

I have one menu_1.php file, containing links to other pages. When such hyperlink is clicked I want that the content of those pages is shown in an iframe in index.php. This iframe must only be active when someone clicks on the link, otherwise it should not show the iframe but the default content in the else statement.

Code: Select all

print '<div id="menu">';
print '<ul>';
print '  <li><h2>Navigation</h2>';
print '    <ul>';
print '      <li><a href="http://mysite.com/otherpage.php?id=2" target="inline” onClick=setKey(1);return false">Menu item 1</a></li>';
….
Please not that the onClick=setKey(1) was my latest attempt to set the condition and I’m sure that I’m doing something wrong there too.


The code in index.php

Code: Select all

function setKey($Key_1)	{
if  (isset($Key_1)){
  		print '<iframe name=inline scroll=yes frameborder=1 width='.$xwidth.'  height='.$yheight.'>';
		print '</iframe>';
		}
 elseif (!isset($Key_1)){
			print '<table width='.$xwidth.' height='.$yheight.' style="background: url('.$path.'load_'.$lang.'.gif) no-repeat;background-position:top center">';
…..
}
}
I tried it before with $_GET[‘nav’] and included that in the hyperlink but this was not working out either. I guess that my question could be summarized as: how do I set a hidden variable in menu_1.php that activates the condition in index.php?

Hope that there is someone to help me out with this…
Michael

Posted: Mon May 08, 2006 12:42 pm
by Christopher
I think you need to get clear what is PHP and what is Javascript. For example this code is Javascript, but seems to be trying to call a PHP function (plus missing a "):

Code: Select all

onClick=setKey(1);return false"

Posted: Mon May 08, 2006 3:06 pm
by michaelm
Christopher, thanks for replying. Do you have any suggestions to have this working the way I want to? I thought that using the onclick event in menu_1.php might be feasible and am indeed mixing languages in my attempt to get this working. So set the condition in menu_1.php and use the result in index.php by using a if (isset) statement...is that a structure that you would recommend and will work? Or must I try something else?

Michael

Posted: Mon May 08, 2006 3:17 pm
by Burrito
you could set the display property of your iframe to 'none' initially. Then when a link is clicked you run a JAVASCRIPT function to toggle that property, and set the src property while you're at it.

That way when the page is first loaded, you'll have your 'default' content, then when a link is clicked, it will show the iframe with whatever you define as the page source.

the alternative (and easier method), would be to have a default page for your iframe and then just use the 'target' attribute of the <a> tag to change the iframe's location on click of a link.