Manipulate Drop-Down List

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devarishi
Forum Contributor
Posts: 101
Joined: Fri Feb 05, 2010 7:15 pm

Manipulate Drop-Down List

Post by devarishi »

How to call a PHP Function, defined in the same PHP Web Page, on a control's events such as onChange even of select tag?

Example:

Code: Select all

 
Support Group <select name="Group">
 
<?php
 while (!$rs->EOF) { 
 echo '<option value="' . trim($rs->Fields['supportGroup']->Value) . '">' . trim($rs->Fields['supportGroup']->Value)  . '</option>';
 $rs->MoveNext();
}
?>
 
</select>
 
Here, I want to manipulate another "select" list "<select name='Items'>" depending upon which Group is selected above. How to achieve it?

I think that onChange event of the first select list I need to call a Function that can manipulate the 'Items' list.

It is just like how it happens on web pages when you select a "State" and corresponding "City" is displayed in another Drop-Down List.

Any help?
Last edited by Benjamin on Mon Feb 22, 2010 8:03 pm, edited 1 time in total.
Reason: Changed code type from text to php.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Manipulate Drop-Down List

Post by jraede »

devarishi
Forum Contributor
Posts: 101
Joined: Fri Feb 05, 2010 7:15 pm

Re: Manipulate Drop-Down List

Post by devarishi »

jraede wrote:Use AJAX. W3 Schools AJAX Tutorial

Can we use AJAX with PHP? So, do I need to learn some basic controls/features of AJAX or have to learn it along with PHP?
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Manipulate Drop-Down List

Post by jraede »

AJAX isn't a language, it's just a way of interacting PHP with JavaScript, so you can run server-side scripts in the background after the page has already loaded.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Manipulate Drop-Down List

Post by Benjamin »

The first thing you need to understand is that PHP is a server side language. Therefore it (PHP code) is neither executed nor sent to the browser. AJAX is the use of a client side language (Javascript) to send http requests based on user events. AJAX can be used to populate child dropdown menus and is the correct solution.
Post Reply