Page 1 of 1
3 frames problem
Posted: Fri Oct 28, 2005 11:29 am
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.
Posted: Fri Oct 28, 2005 11:36 am
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">
Posted: Fri Oct 28, 2005 11:37 am
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.
Posted: Fri Oct 28, 2005 12:10 pm
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
Posted: Fri Oct 28, 2005 12:16 pm
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

Posted: Fri Oct 28, 2005 12:37 pm
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!!!
Posted: Fri Oct 28, 2005 1:03 pm
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
Posted: Fri Oct 28, 2005 1:34 pm
by Burrito
Posted: Fri Oct 28, 2005 1:44 pm
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?
Posted: Fri Oct 28, 2005 1:48 pm
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.
Posted: Fri Oct 28, 2005 2:06 pm
by ajarmeh
thanks burrito, i will CAREFULLY read your tutorial and let you know about any difficulties.