文本框onchange调用php函数 [英] textbox onchange call php function
本文介绍了文本框onchange调用php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从HTML表单文本框中的onchange调用php函数?我尝试过
How can i call a php function from onchange on an html form textbox? I have tried
<input onchange="phpfunction()" ..... >
<?php
function phpfunction() {
my function
}
?>
有帮助吗?我似乎无法弄清楚.
Any Help? I Can't seem to figure it out.
谢谢
推荐答案
您必须进行ajax调用并将其发布到PHP.
You have to do an ajax call and post that your PHP.
示例:
HTML:
<input name="blah" onchange="mainInfo(this.value);">
JavaScript函数(AjaX)
function mainInfo(id) {
$.ajax({
type: "GET",
url: "dummy.php",
data: "mainid =" + id,
success: function(result) {
$("#somewhere").html(result);
}
});
};
PHP
<?php
if(isset($_GET['mainid'])){
mainInfo($_GET['mainid']);
}
?>
这篇关于文本框onchange调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文