-->>Hello,My problem is how will a trigger a php Function based up on Change event of a listbox value.
My Page has the Field as those in the screenshot below the code:
So when a driver is selected on the list all his/her details should be populated in the remaining fields on the page as I already capture the Value of a driver from the Listbox.
My php code for catching up drivers details is:

public function Drivers_Details()
        {
            $sql="SELECT * FROM school_drivers WHERE idDriver=".`$_POST["Driver_ID"]`."" ;
            $query=mysql_query($sql);
            $find=mysql_fetch_array($query);

            if($find)
                {
                $find["First_Name"];
                $find["First_Name"];
                $find["Second_Name"];
                $find["Last_Name"];
                $find["Gender"];
                $find["Mobile_Number"];
                $find["Residence"];
                }
        }

Note that $_POST["Driver_ID"]is the value from the listbox that populates driver's names.
I got some suggestions about jquery and java but I'm NOT good at all with the languages.
Much appreciations.
6d0e279a52d7d4e7991592be7b49936b

Hi Bile

Your problem lies in the separation of client side and server side code, the simplest solution I can suggest is something as follows:

In your PHP part of your application you can check if the $_REQUEST variable has been set for the drop down box. If it has, then you can call your function, problem is your function does not return anything meaningful to use when outputting your form variables.

Your onchange event on the drop down box will have to perform a refresh of the page or call an AJAX script to populate the input boxes.

So lets go through logic briefly:

First page load:

1.) check if request variable is set for drop down - do nothing
2.) display the form with default values

User then chooses from drop down - fires a submit ?

Second page load:
1.) check if request variable is set for drop down - yes - go get values from function
2.) display the form with values retrieved from the function

Hope this helps with your problem.

-->>Thats exactly what I need andrevanzuydam.
The fact is I tried to show the necessary requirements I have up to now and form there to let suggestions on how to mix things out so as to access those values captured in the function.
And I admit that My function does not return anything it just shows how will I get the Values and so is My stuck point...
And I hope that you will help Me do things out,so how do we get started?
Thanks andrevanzuydam.

Best is if I make you a video on how to deal with this issue and add it on my channel, give me a chance to do this, it will help other people too, this is a common issue I experience.

My example is mainly to use PHP to do everything, opposed to using AJAX and javascript to manipulate the form elements. The principal is a simple hidden input for an action which passes to a switch statement. Have a look at the link for the video and sample code.

Click Here

-->>Tanx...
Tanx again and tax a looot andrevanzuydam.
What can I say?...
You have solved a major issue in My project,becouse most of the Update and delete information ages I have to do the same thing to pull the information before perfoming further operations.
The video is helpful and I suggest You as well post it in the code snippets web development forum.
One final thing is that when the data is picked how do I assign back the value of a gender to My dropdown listox?
216e336fc3674f24d0d5be24ac1853f8
As to this made Me think of tweaking some things out "NOT PROFESSIONAL I HOPE" by adding an extra option tag to the select dropdown list in My html page as follows:

<select name="Gender">
  <option value="Select">---Select Driver's Gender---</option>
  <option value="Male">Male</option>
  <option value="Female">Female</option>
  <option selected="selected" value="<?php echo $_REQUEST["Gender"]; ?>"><?php echo $_REQUEST["Gender"]; ?></option>
</select> 

And as You can see when the page is loaded the drop downlist is empty as selected option/dfault has no value currently until the whole process of specyfying the driver and all data are pulled thats when the $_REQUEST["Gender"] is assigned the valu of drivers gender and the list possesses 3 genders with one of the gender repeated twice (BAD IMPRESSION)
and the php side I have this:

/*  THE FUNCTION BELOW IS FOR FETCHING DRIVERS DETAILS ONCE SELECTED FROM THE LIST ON THE drivers_update.php PAGE */
    public function Drivers_Details($Driver_ID)
        {
            $sql="SELECT * FROM school_drivers WHERE idDriver=".$Driver_ID."" ;
            $query=mysql_query($sql);
            $find=mysql_fetch_array($query);

            /*I used this hidden input text to hold the ID of the selected driver so as to refference it during update*/
            $_REQUEST["interface"]=$Driver_ID;

            if($find)
                {
                $_REQUEST["txtFirts_Name"]=$find["First_Name"];
                $_REQUEST["txtMiddle_Name"]=$find["Second_Name"];
                $_REQUEST["txtSurname"]=$find["Last_Name"];
                /*This is the option that holds the gender of the driver in My html*/
                $_REQUEST["Gender"]=$find["Gender"];
                $_REQUEST["txtResidence"]=$find["Residence"];               
                $_REQUEST["txtMobile_Number"]=$find["Mobile_Number"];
                }           

        }
    /*  THE FUNCTION BELOW IS FOR FETCHING DRIVERS DETAILS ONCE SELECTED FROM THE LIST ON THE drivers_update.php PAGE ENDS  */

That's it can we make it a little professional?
Bigup Man.

I think it is easier than you think, remember you have the gender coming from the database already, your thinking is that the genders are static, my suggestion to solve this is as follows, excuse the code if it does not parse first time, I write it without testing it, it is the principal that is important.

$gender = array ("Male", "Female");


echo "<select name=\"selGender"\>";

foreach ($gender as $gid => $gendervalue) {
  $selected = "";
  if ($_REQUEST["selGender"] == $gendervalue) {
    $selected = "selected";
  }
  echo "<option {$selected} value=\"{$gendervalue}\"> {$gendervalue} </option>";  

}

echo "</select>";

That should do it for you!

And, please don't forget to correct the spelling on "First Name"

-->>tanx Man,My hand is down now.
I dont want to over do it.
This really was helful.
Thanks andrevanzuydam.

-->>Thanks as well for reminding Me on "$_REQUEST["txtFirts_Name"]" name thing I managed to wind through it all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.