Page 1 of 1

Manipulate Drop-Down List

Posted: Mon Feb 22, 2010 3:00 pm
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?

Re: Manipulate Drop-Down List

Posted: Mon Feb 22, 2010 6:33 pm
by jraede

Re: Manipulate Drop-Down List

Posted: Mon Feb 22, 2010 6:37 pm
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?

Re: Manipulate Drop-Down List

Posted: Mon Feb 22, 2010 6:41 pm
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.

Re: Manipulate Drop-Down List

Posted: Mon Feb 22, 2010 8:06 pm
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.