Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to in PHP or JS? Don't know???

Status
Not open for further replies.

BobMCT

IS-IT--Management
Sep 11, 2000
756
US
Fellows:
On one of my html pages created with php there are two prompt fields. The first is a select list that is table driven. The second right now is empty. However, its contents should really be populated by entries retrieved from a DB based on the selected entry from the select list above it.

How would one go about triggering the event which would return control to the php program allowing it to perform the query and deliver the populated second select list?

I am thinking an "on_something" which would pass control back to the server script along with the value of the selected item.

Can anyone please identify the terminology for this which would allow me to further research how it can be made to work?

Thanks in advance.

B
 
I think first that you must build a better model of what is happening in web pages in general.

By the time the web browser has rendered the page, there is no connection between the browser and the server any more. There is not mechanism by which controlled can be passed anywhere.

What you can do is make the web browser open a new connection and send data to the server, which in turn sends a new version of the page with the second dropdown populated.

For that, you can use the JavaScript "onchange" event to run JavaScript code which sumbits the form. Just keep in mind that should a user have JavaScript turned on in his browser, he won't be able to use the site unless you provide a submit button in the appropriate place.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
PHP is a serverside langauge, that means it cannot interact with Javascript. The Javascript part of the webpage, must somehow, submit the information to the server, so that the PHP can use it.

The best bet for populating selects through PHP, is to ignore the Javascript completely, and just have a small submit button next to the Select box so that it is pressed after the option is selected. This will then pass the value of the selected option to the server. Which you can then use to run a query and populate the second select box.

There is a way to make it submit automatically through Javascript using an on_click event, and the calling the submit funtion, but that has ben known to cause problems.

IF you want to populate instantly upon selection of the frst one, it has to be done via javascript and is out of the scope of thes forum. If you can allow for the page to vbe submitted and refresh, then using the submit button is the way to go.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks guys.
I thought it would be a client side event (javascript) which could trigger the php again on the server to send back the same page with the 2nd field populated as needed. But I DO like the optional submit button idea adjacent to the field.
This is what I was hoping I would get - good ideas.

Thanks again.

B
 
It could be done using AJAX (HTTPxml???) routines in Javascript.
[ul]
[li]You open a connection to a smaller PHP script, passing it the selected value.[/li]
[li]It returns the value that is needed to put in the second field[/li]
[li]Your Javascript script "does the right thing" :)[/li]
[/ul]

I can't help you with the Javascript since I've only used the HTTPxml??? functions once.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top