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 function is designed to take the selected index of dropdown as parameter and return related values to populate the textboxes. However I 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.
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;
}
}
Trying to elaborate more on my comment above...
Basically, this is what you are trying to do: (Correct me if I'm wrong)
This is possible with PHP and JS, but in more general terms it's possible with Ajax.
You need to:
Current JavaScript libraries (jQuery, etc) provide a lot of this functionality. For example, here's jQuery's documentation on its Ajax functions.