Home:ALL Converter>using javascript and php server to set textbox value after a dropdown value is selected

using javascript and php server to set textbox value after a dropdown value is selected

Ask Time:2011-02-19T19:47:30         Author:luhfluh

Json Formatter

I am using a form which will retrieve values to set the textbox inputs after a dropdown value is selected. My problem comes from the fact that my php server fnction is designed to take the selected index of dropdown as parameter and return related values to populate the textboxes. I however can't figure out how to combine the php function and the javascript which will do the textbox value setting. Below is my sample code. Any help appreciated.

As can be seen below, displayGamsProjectInfo(fe) function calls the database function ddGamsProjectInfo($gamsId) but how can I can I allow the php function to 'pick' the selected dropdown index without the user POSTing the form values (after maybe button clicked)

javascript/php:

    <script language='javascript'>function displayGamsProjectInfo(fe){
   document.all.FACILITY_RC_ID.value= '';
   document.all.FACILITY_FACULTY_ID.value= '';
   document.all.FACILITY_SUPVSOR_NAME.value= '';
   document.all.FACILITY_SUPVSOR_TELNUM.value= '';
   document.all.FACILITY_SUPVSOR_EMAIL.value= '';
   if(fe.value != null && fe.value != ''){\n";
   $getGamsInfo = FacilityDB::getInstance()->***ddGamsProjectInfo()***;
   if($getGamsInfo && $getGamsInfo != null){ 
      if($row = oci_fetch_array($getGamsInfo)){ 
        print "document.all.FACILITY_RC_ID.value= '$row[RES_CENTER]';
        document.all.FACILITY_FACULTY_ID.value= '$row[FACULTY_ID]';
        document.all.FACILITY_SUPVSOR_NAME.value= '$row[STAFF_NAME]';
        document.all.FACILITY_SUPVSOR_TELNUM.value= '$row[STAFF_TELNUM]';
        document.all.FACILITY_SUPVSOR_EMAIL.value= '$row[STAFF_EMAIL]';\n";                      
        }
      }                                             
   print "}\n
}</script>"

php function:

public function ddGamsProjectInfo($gamsId){
if(!isset($gamsId) || $gamsId == '' || $gamsId == null)
   return null;
else{
   $sql = "....";       
   $stmt = oci_parse($this->con, $sql);
   oci_execute($stmt);
   return $stmt;
}

}

Author:luhfluh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/5050591/using-javascript-and-php-server-to-set-textbox-value-after-a-dropdown-value-is-s
yy