更改下拉列表时,应该会调用一个php函数。
在PHP函数中,我将进行一些计算。稍后,我需要设置文本框的值,否则PHP函数应该返回一个值,该值应该在javascript中捕获,并将该值设置为textbox控件。
我的html函数是
<select name="sltLeaveType" id="sltLeaveType" class="formSelect" onchange="TotalCountsOfPL(this.value)">
<?php
<option></option>
<option></option>
</select>在PHP中,函数放在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()函数。
发布于 2011-05-24 17:46:20
您不能从js或html调用php函数,但您可以通过ajax调用php函数来实现这一点,在php函数中您可以执行计算,然后将结果值返回给js,因此您可以通过js调用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...
}发布于 2011-05-24 18:34:34
插入你的函数到一个php文件中去执行,然后你就可以用ajax调用php文件了(我建议你使用jQuery )
///////////////////////// foo.php
<?php
Function foo (){
// Your process
}
foo();
?>
///////////////////// text.html
<select name="test" id="test" >
<option>.....</option>
.
.
.
.
</select>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
<script type="text/javascript">
$('#test').change(function(){
$.ajax({
type: "GET",
url: "foo.php",
success:function(){
// Your function after execute foo.php
}
})
})
</script>https://stackoverflow.com/questions/6108495
复制相似问题