Click to See Complete Forum and Search --> : controlling and passing varibales -- frames
muratisik
11-20-2003, 07:08 AM
Hello,
I am new to javascript and I am playing a round with the example on this page:
http://www.pageresource.com/jscript/jex12.htm
For a beginner, it is a nice code. what I am trying and failing to do is to get the "What is cool" button to refresh the right frame and then have "Me!" writtin like a regular writing, instead of a text box. Is this possible? If so can anybody help me sort out the code?
Thanks in advance
Murat Isik
fredmv
11-20-2003, 07:17 AM
Check the attachment for a simple example.
muratisik
11-20-2003, 07:27 AM
Thank you:)
I actually want to do this with "Write "Hello, World!" to the other frame." being a button. How can I modify this example into a button?
fredmv
11-20-2003, 07:29 AM
No problem. I just modified it so it's a button. Check the attachment.
muratisik
11-20-2003, 07:37 AM
Thank you:) This is great for a beginning!
Is there a way I can modify this code so that when the button is clicked the right page refreshes and it assigns a new value to a variable in the right frame.
I know maybe I am asking too much, but I am a newbei and I have this mapping project to complete :(
It works perfectly on a single php page, with buttons pressed to move up-down the map or zoom. Some thing like the example on http://mapserver.gis.umn.edu/doc35/phpmapscript-byexample-howto.html#letszoom
Now I have to do it in frames and thus have buttons on one side to pass the variable values to the other side and get it refreshed with new values.
I will be very glad if you can hint on any way to use your nice code for passing variable values:)
have a nice day
murat isik
fredmv
11-20-2003, 07:41 AM
Alright, I just made it so it changes a variable inside the other frame's document and then prints it inside an element. Check the attachment.
muratisik
11-20-2003, 07:51 AM
Great!
This is the kind of stuff I could have found anywhere else. Simple and understandable. I am sure it is ok to put this right frame script inside a php script and I hope there is a way to "extract" this "text" variable and use it as php variable like (after your nice script):
$text_to_be_written=$HTTP_POST_VARS["text"];
echo $text_to_be_written;
Is there? (If I am not taking too much of your time.)
Thank you for helping this newbei. I am sure if I once get the logic of how to pass variable values from javascript into php then I will have overcome most of my problems. But you know how hard it is for a beginner to understand even the basic logics
Have a nice day:)
Murat Isik
fredmv
11-20-2003, 07:56 AM
No problem, and yes, I understand completely. As you said, it can be quite hard to understand even the simplest concepts when new to something like this. Which is why I'm trying to provide easy to understand examples for you. As for your question, you'll have to use a slightly different approach to obtain that PHP variable. Here's the basic idea. You will need to print out that value but inside of some JavaScript. For example, you could do something like this to get it:var foo = "<?php echo $_POST['bar']; ?>";Then you could easily use this along with the script I previously wrote. It should be quite easy to customize. All you're really doing is printing these values dynamitcally generated by PHP into JavaScript code.
I hope that helps you out.
muratisik
11-20-2003, 08:01 AM
Thank you:)
I will try this right way...
Have a nice day
Murat Isik
fredmv
11-20-2003, 08:04 AM
No problem. Thanks, you too. :D
muratisik
11-20-2003, 08:22 AM
I made a small modification to your bar.html :
<script type="text/javascript">
var foo="<?php echo $_POST['bar']; ?>";
onload = function() { document.getElementById('text').innerHTML = "Current value of the <em>foo</em> variable: " + foo; }
</script>
<div id="text"></div>
<?php
$bar= $_POST['bar'];
echo $bar;
?>
I thought this would get me to have $bar set with the value of "bar" passed from the other frame. But it did not work :(
What I am thinking is that if I can somehow get the varibale from the left frame and load it into $bar like php variable then I can do the rest just like a regular php code. Printing is like a test of loading the variable and I see that my little modification could not do it. Any ideas, sir?
Thank you for helping:)
Murat Isik
fredmv
11-20-2003, 08:25 AM
For that to work correctly you would need the previous page to have a form which has an element named bar that has the name of that file as the form's action. Otherwise, that will return no value.
muratisik
11-20-2003, 08:34 AM
Thank you but being a newbei, I have not understood a word :(
Do you have any simple examples? Anything with the basic logic will be ok :)