3 frames problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ajarmeh
Forum Newbie
Posts: 9
Joined: Fri Oct 28, 2005 11:06 am

3 frames problem

Post by ajarmeh »

hi.
i have a page that consists of 3 frames, the second and third frames contain radio buttons, the top frame contain a button, i want to be able to access the values of the radio buttons once I click on the button on the first frame, i want to use PHP because i will be forming a Query based on these radio buttons. any Ideas?????? THANKS in advance.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

using php to access the variables across frames will be difficult as they (all pages (frames)) have to be sent to the server in order for php to handle the variables.

your best bet would be to just access the variables with JS across the frames.

something like:

untested

Code: Select all

<!-- this is frame one -->
<script>
function getFrameTwoVal()
{
    document.getElementById("frametwoval").value = top.frametwoname.getElementById("frametwovar").value;
}
</script>
<input type="hidden" name="frametwoval" id="frametwoval">
<input type="button" onClick="getFrameTwoVal()" value="get value">

<!-- this is frame two -->
<input type="text" name="frametwovar" id="frametwovar">
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

A combination of JavaScript and PHP.

When a value is selected in the radio boxes, make the frame that you're building the query in redirect to http://current_url.tld/?somevalue=something then read the value from $_GET.

Alternatively, have the user submit the form by clicking a button and put the target attribute in the <form> tag so that the data goes to the other frame.
ajarmeh
Forum Newbie
Posts: 9
Joined: Fri Oct 28, 2005 11:06 am

Post by ajarmeh »

ok, guys, suppose that i got the values of the frame radio buttons using Java Script, then how would i pass these values to PHP (passing variables between Js and PHP)? iam sorry it might seem as a silly Question, but i am new to both PHP and JS. thanks again
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It's a common question... and one that doesn't have a neat answer.

because JS runs on the client side and php on the server it's not simple.

One way, slightly Old skool is to do something like:

Code: Select all

var some_js_var = 'somevalue_to_pass_to_php';

if (some_event_happens) window.location = 'thisphpfile.php?some_var=' + some_js_var; //Redirect
Then in the PHP code you would get that variable like so:

Code: Select all

$some_var_from_js = (isset($_GET['some_var']) ? $_GET['some_var'] : FALSE);

echo $some_var;
The most modern methodlogy uses AJAX, but if you're new to all this it might be beyond you right now.

Check out http://xajax.sourceforge.net to learn more about ajax though :)
ajarmeh
Forum Newbie
Posts: 9
Joined: Fri Oct 28, 2005 11:06 am

Post by ajarmeh »

THANKS...... d11wtq.... you are my hero today!!! LOL! i will try the stuff you told me and get back to you if anything goes wrong... BIG THANKS!!!
ajarmeh
Forum Newbie
Posts: 9
Joined: Fri Oct 28, 2005 11:06 am

Post by ajarmeh »

d11wtq, can you please help me doing this using xajax??? I already downloaded the library and iam reading about it... please guide me through this.
thanks
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

check this out:

viewtopic.php?t=34665
ajarmeh
Forum Newbie
Posts: 9
Joined: Fri Oct 28, 2005 11:06 am

Post by ajarmeh »

ok Burrito,
now lets sumarize the whole thing,
when i click on the buttom on the first frame, you want me to activate a JS function that gets the 2 radio buttons on the second and third frames. fine, i can do that, then i need the same action (CLICK) to send these variables to a PHP file for processing, can i call a PHP file from within a JS function?
or am I missunderstanding you?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

indeed you can with AJAX or XMLHttp.

It's really one in the same, AJAX actually uses the XMLHttp object but includes a much larger library.

if you look at my tutorial it will walk you through making a http request (via post or get) to another page where you can send variable information to the server without changing the page or reloading the current page.
ajarmeh
Forum Newbie
Posts: 9
Joined: Fri Oct 28, 2005 11:06 am

Post by ajarmeh »

thanks burrito, i will CAREFULLY read your tutorial and let you know about any difficulties.
Post Reply