PDA

View Full Version : Passing parameters; JS to PHP and back


dlowery
09-19-2002, 11:44 PM
The situation:
A page that is a template for a photo gallery.

Elements
1. A JavaScript menu system that allows the user to select from a number of categories. The choice reduces to a 'category code' that goes to ...

2. Dynamic Photo Display generated by PHP script. Thumbnails are displayed on the page and a click on an image pops-up a new window with the full-sized image. This works great, thanks to PHP and Internet resources.

3. The passing mechanism: at the moment I am trying to use a query string in the menu system to call a small PHP page. There, the single 'category code' string is processed into an image directory identifier and a title string for the category to be displayed.

JS: onclick="director.php?goal=bonus01"; // this is a demo string

I know the director.php script works because a couple of debugging echo statements produced the correct evaluations.

THE PROBLEM is, I don't know how to get this info back to the calling page so it can process the data and produce the table cells to show the thumbnails. Once the director.php file does its job, things come to a halt.

Yup, I'm a newbie and brainwashed in structured programming techniques. <sigh!>

Just Arrived in my flustered brain: Can I call a PHP function in the JS menu script (instead of the URL query string)??

Any ideas?

dlowery

Spookster
09-20-2002, 05:42 AM
PHP and Javascript cannot interact with each other. PHP is processed on the server whereas Javascript is processed on the clients machine or more specifically in the clients browser. In order to call a php that contains functions and such either a POST or GET request must be made to the server via hyperlinks or forms. When you load the php page into a browser there will be no php coding in the page. The way it works is when a php page is requested the php engine grabs that page and processes it and does whatever it is told to do then outputs nothing but HTML coding and sends that to the browser.


I'm not sure I understand what you mean when you are wanting to get info back to the calling page. When you click on the link to go to the director.php page that page should load in the browser. That page should contain all the necessary coding to display whatever it is you want to display based off of the parameters you sent to it via the query string as you noted in your demo link.

Is your site in a frameset or something?

mordred
09-20-2002, 01:16 PM
If you are interested in what mind-boggling efforts people have done to get JavaScript to retrieve data from php scripts, see this site on remote scripting (http://ashleyit.com/rs/). But it requires a firm knowledge of JavaScript, PHP and how the HTTP-client/server architecture works. With that you can retrieve all necessary data you want from PHP, but once you have it on your client's side, you have to rely on JavaScript to redraw the layout i.e. to manipulate the document (like changing an images source or add new menu items).

dlowery
09-22-2002, 01:00 AM
Thank you Gentlemen for your input.

I got a thing working...sorta like Rube Goldberg...by writing my JS output to a hidden form field and then accessing that field from PHP on the same page. Seems to be working pretty well. Oh, it's a tiny form with just that one field.

dlowery