0

i got the problem of accessing variable outside iframe.

//a.php
<?php
$a="text";
?>
<iframe src="b.php"></iframe>

//b.php
<input type="text" value="<?php //i want $a to be put here ?>" />

Is it possible to access $a from b.php?

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by ko ko
0

Hmm. You could use a session variable and get javascript to refresh the iframe.
I think this was an early method for ajax.

You don't even have to use a session variable though, you could pass the variable as a querystring (although I think you're limited to length here). Quite a few ways you could do it I suppose.

Are you not able to use an include file for b.php?

<?php
$a="text";

include("b.php");

?>

Edited by diafol: n/a

0

actually i wish to put some tables into b.php but it will mess up my divs if i use include directly.

0

Really? I'd look at how a.php b.php are formed in that case. Using an iframe is not the way to go (IMO).

0

ok, solved. i assign value through a form.

//a.php
<form action="b.php" target="frame" method="post" >
<input type="hidden" name="hide" value="<?php echo $a; ?>" />
<input type="submit" value="Go" name="go" />
</form>
<iframe src="b.php" id="frame" name="frame">
</iframe>

//b.php
<input type="text" value="<?php echo $_POST[hide]; ?>">
0

If solved ? Then mark it as 'Solved' with below link 'Mark as Solved' or something similar.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.