Page 1 of 1

PHP Script that uses ajax

Posted: Mon Aug 04, 2008 6:02 pm
by CoolAsCarlito
I have a drop down select box and need to know how to recall all the info that option has and have it post it's info into the form fields below it. How is that done. Because it'll give the user the ability to edit the info and then click "Update" and it'll change the info.

http://www.kansasoutlawwrestling.com/edittitle.php

I was told this would help but I'm still clueless. Someone with an intelligent mind please help me please:

You need AJAX for that. The drop down menu would need an onchange="ajax_function()" inside of the <select> tag. You would have to define ajax_function() as a javascript function elsewhere in the document.

Essentially how it works is this (extremely simplified): the ajax/javascript function that is called from onchange will check what the current selected value in the menu is and send it as a parameter to a .php file. The php file retrieves the parameter with the $_POST or $_GET arrays. The file pulls what ever info you need from the database, formats it, and gives it back to the javascript function. The javascript function then sets some other div's inner HTML to whatever was retrieved from the php file.

Re: PHP Script that uses ajax

Posted: Mon Aug 04, 2008 7:33 pm
by califdon
Once a page has been sent to the browser, PHP is done. To respond to something the user does in the browser, you have to use Javascript. If you have all the info you need in the HTML page, you can do it just with Javascript. If you need to interact with a database back on the server, then you have two choices: (1) send a new request back to a PHP script on the server that sends a whole new page back to the browser, or (2) use AJAX, which is basically Javascript that uses a particular built-in object called XMLHttpRequest to send an asynchronous request back to a PHP script on the server that just sends DATA back to the browser, not a whole new page. The XMLHttpRequest code must receive the data and then update the page.