问题描述
在更改下拉列表时,应调用一个php函数.
On change of the dropdown list, A php function should called.
在PHP函数中,我将进行一些计算.稍后,我需要设置文本框的值,否则PHP函数应该返回一个值,该值必须在javascript中捕获并将该值设置为文本框控件.
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.
我的html函数是
<select name="sltLeaveType" id="sltLeaveType" class="formSelect" onchange="TotalCountsOfPL(this.value)">
<?php
<option></option>
<option></option>
</select>
然后在PHP函数中将其放置在D:/Project/EmployeeDetails/EmpLeave.php
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;
}
所以现在[请向我提供JQuery函数来调用此Php函数可以在下拉列表上的每次更改时调用GetTotalPL()函数.
So now please [prvide me the JQuery function to call this Php functionto get call the GetTotalPL() function on every change on the the dropdownlist.
推荐答案
您不能从js或html调用php函数,但是可以通过ajax调用php函数来执行此操作,然后在其中执行计算,然后将结果值返回给js,这样您就可以将js转换为html ...
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...
更新:
<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...
}
这篇关于在更改下拉列表showld上调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!