View Full Version : Help with dropdown

11-05-2009, 04:19 PM
:confused:I am writing php code to select data via a dropdown list from a mysql table of materials for a transaction log. I want to be able to insert a new material if it is not in the dropdown list. How can this be done without leaving the page, inserting a new record, returning to the page, refreshing the page to repopulate the dropdown?

Do I need to use js? or can this be done with php?

This seems like a situation which I would think many programmers have a need for.

11-05-2009, 05:36 PM
It can be done using php but if you don't want to have to "refresh" a page, you can use AJAX or any of the javascript libraries to achieve that.
Example using jQuery (http://thesteveblog.blogspot.com/2009/03/jquery-login-without-refresh.html)

11-05-2009, 08:02 PM
I can understand the desire to "not leave" the current page. Your situation is exactly what Ajax techniques were developed for.

PHP script happens at the server and results in data that is sent to the client.
Javascript happens at the client after the server sends the script code there.

Ajax, not being a 'language' but a technique, is all about using JS on the client,after to reach back to the server for additional information. When the ajax object gets an answer back from the server, JS reads the response and uses it to update the page.