PDA

View Full Version : Passing variables to frames


niftyme
02-24-2005, 03:41 AM
This is the problem I am having:
I have an index page where I obtain input from the user (for example their date of birth). This information is passed to Page2. Page2 has frames. Outside of the frames I can access the user's input. But within the frames I can't seem to be able to get the value. The date is stored in a global variable.

Here are snippet's of code:

##Variables
my ($BDAY, $path_info, $script_name);

##Obtaining value from the index page
if ($q->param('birthday')) {
$BDAY = $q->param('birthday');
}

##Creating frame
$path_info = $q->path_info;

##Printing the fames
if (!$path_info) {
&print_frameset($BDAY);
exit 0;
}

##Printing the different frames
&print_html_header; ##HTML headers
&print_content if $path_info=~/content/; ##Left pane with links
&print_expand($BDAY) if $path_info=~/expand/; ##Expanded graph
&print_analyse if $path_info=~/analyse/; ##Options to do analysis
&print_end; ##End HTML
&print_error;

##Setting up the frames
sub print_frameset {

my $birthday = shift;
$script_name = $q->script_name;

print "<html><head><title>$TITLE</title></head>";
print "<frameset cols='8%,92%'>";
print "<frame src='$script_name/content' name='content'>";
print "<frameset rows='70%,30%'>";
if ($birthday) {
print "<frame src='$script_name/expand' name='expand'>";
print "<frame src='$script_name/analyse' name='analyse'>";
}
else {
print "<frame src='$script_name/error' name='error'>";
}
print "</frameset>";
print "</frameset>";

exit 0;
}

One of the frame's contents:
sub print_expand {

my $birthday = shift;
print $q->h3("My birthday is on: $birthday");

}

In this frame all it prints is "My birthday is on: " it is not printing the variable.

I cannot figure out why I cannot get the value in the subroutines. I have checked and the value does get passed from the index page to this page. I can print it from the global variable $BDAY but not from the sub routines that form the frames.

I have spent almost 2 days on this and I am starting to go insane!! I would appreciate any hints/help/suggestions you can provide.

Thanks!
Me

mlseim
02-24-2005, 04:09 AM
First of all, I would never use frames.

You could use cookies .... Perl mixed with Javascript,
where Javascripting does the transferring and displaying
between frames.

But, alas ... frames to me are so broken and
illogical, I can't seem to figure out where the
problem is.

sorry. :o

andyede
02-24-2005, 07:59 AM
from a server side programming point of view there is no difference between a page in a frame and the parent frame itself. if you think the frame is messing up the script then send your browser to the page within the frame in the parent window and see if it works ie. make the script print out 1 page that isn't working at a time, in the main window. if it doesn't then its your code thats at fault not the frames.

i've used frames a few times and although have had a few related problems i've been succesful most of the time. I am a big fan of keeping it simple so i try and get away with as little complicated stuff as i can.

If you want a good example of complicated framing take a look at the site i made for my mate http://www.animationsupplies.net/ (http://www.animationsupplies.net/). The nav bar is in an Iframe. The Iframe is made in the page by a javascript document.write which is stored in a seperate file. the seperate file is actually a cgi program that detects if the user is logged in or is an admin etc and adjusts the height of the Iframe to fit the menu. The contents of the iframe is the navbar itself which is created by another script that adds apropriate links to an html template page.

I was amazed it worked too!