Page 1 of 1

Newbie: help with javascript+PHP interactions

Posted: Mon Jul 14, 2003 5:41 pm
by registering
Hello all,

I'm new to both javascript and PHP and am having trouble seeing the "big
picture". I thought I had it down but I added some javascript and am now
lost conceptually.

I'm building menus dynamically via javascript, and would like to pass on
the current values of these menus to a PHP script which creates an image
for me (a graph of the values).

Normally I would do something like this:

Code: Select all

<form action="graph1.php?$query_string" name=form7 method=post>
   <input type="submit" value="Send form">
   </form>
which works fine when the page is first loaded ($query_string is given
default values). However the intent is for the user to change the menus'
values, hit "submit" again and the image will be recreated.

How do I do that so the image is recreated in the correct place when the
user hits the "submit" button or changes a menu selection? That is, I can
do something like this:

Code: Select all

<form action="stacked.php" name=form7 method=post onSubmit="return false;">
      <select name="Table" onchange="CallGraph()">
         <option selected=true value="spacekeeper">Table</option>
      </select>
   </form>
so that when the user changes a selection, "CallGraph()" is called which
is a javascript function that builds the $query_string to pass to graph1.php.
However I'm lost as to what to do next. How do I simply call graph1.php from
within CallGraph() so that the image will appear in the proper place??

You can view the code at http://www.mindspring.com/~jc416975/stacked.html for reference.
(NOTE: Other applications this script depends on aren't running currently so
you get errors if you hit the actual button). This is the html that stacked.php creates,
which also creates the javascript you see in stacked.html.

Thanks for any pointers, it's greatly appreciated.

Posted: Mon Jul 14, 2003 7:04 pm
by registering
Sorry for the double post: you can view the actual stacked.php code at http://www.mindspring.com/~jc416975/stacked.php, however it won't execute.

If there was a way I could "reload" the page without $query_string being initialized to its default values, but rather take the menus values, that's probably best, however I don't know how to do that. Since the menus only get changed via javascript, the PHP code has already finished executing, which is why I thought I could tie a button to call graph1.php explicitly, but I'm not sure how best to do that. :(

Posted: Tue Jul 15, 2003 4:07 pm
by registering
Okay, I found out you cannot do what I was trying to do. Rather, I need to reload
the entire page, passing it whatever values the user just dynamically filled-out via
javascript.

So I simplified my code and have just 1 big form in jtest10_home.php declared like this:

Code: Select all

echo "\n<form action="jtest10_home.php?<?php EchoScript.php ?>" name="mainForm" method="get">";

and my graph image declared like this:

Code: Select all

echo "\n   <img src="jtest10_graph.php?<?php EchoScript.php ?>" alt="Graph_" . $counter . "" name="Graph_" . $counter . "" border="0">";

My ENTIRE EchoScript.php is this:

code:
<?php
error_log("\n\nhello", 3, "/nerr/html/php.debugfile");
?>



When I change my menus and hit "submit" the URL changes with the real values, like this:
http://192.168.0.120/jtest10_home.p...&site=FS&table= etc....

However EchoScript.php never gets called and I'm lost as to why. There are no spaces or blanks before the "<?" in EchoScript.php.....php.debugfile exists and has write permissions for everyone..

The intent is to simply have EchoScript.php $_GET all of the variables in the URL and echo them back, so when I call jtest10_*, the correct string will be passed to them....

Any ideas why EchoScript.php never gets called? I'm sure it's something really dumb. :(