Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

jquery - on Change of dropdown list showld call the php function

On change of the dropdown list, A php function should called.

Inside the PHP function I will do some calculation. Later I need to set the value of a text box or else that PHP function should return a value that value shoul be catch in the javascript and set that valu to the textbox control.

My html function is

<select name="sltLeaveType" id="sltLeaveType" class="formSelect" onchange="TotalCountsOfPL(this.value)">
        <?php
      <option></option>
      <option></option>
</select>

And in PHP function is placed in D:/Project/EmployeeDetails/EmpLeave.php

class clsGetTotalPL 
{
    function GetTotalPL($EmployeeId)
    {       
        $query = "select count(leave_request_id) from hs_hr_leave_requests where leave_type_id='LTY002' AND employee_id=".$EmployeeId.";";
    return $query;
}

So now please [prvide me the JQuery function to call this Php function to get call the GetTotalPL() function on every change on the the dropdownlist.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't call a php function from js or html, but you can do that by ajax call to a php function where you can perform your calculation and then return the result value to js, so then you can do by js to html...

Update:

<select name="employee" id="employee" onchange="getIPL(this.value);">
   <option value="">Select Employee</option>
</select>    

function getIPL(id)
    {
            $.ajax({
                       type: "GET",
                       url: "EmpLeave.php",
                       data: "emp_Id =" + id,
                       success: function(result){
                         $("#somewhere").html(result);
                       }
                     });
    };


 // Empleave.php file....
  if(isset($_GET['emp_Id'])){
     GetTotalPL($_GET['emp_Id']);
 }

 function GetTotalPL($id){
  // do your calculation...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...