dousi8931 2012-09-13 20:57
浏览 66
已采纳

将表单字段值传递给PHP文件

I'd like to do a dynamic search function using jQuery and PHP. I'm struggling passing the HTML form field to the JQUERY function (which would then get passed to the PHP file).

My major questions are:

1) How do I pass form "Input" field into Jquery function?

2) How do I get the PHP result in the form "Output" field?

I currently have... (simplified)

JQUERY:
$.get("SEARCH.php", {"_input" :  $('input[name=input]').val()},
function(returned_data) 
{
   $("input[name=output]").val(returned_data);
}


SEARCH.php:
$input = 'Welcome ' . $_GET['_input'];
echo $input;
//should be "Welcome" plus whatever I type in to "input"



HTML FORM:
input: <input type="text" name="input" value="" /> 
output: <input type="text" name="output" id="output" />         

Thank you!

  • 写回答

2条回答 默认 最新

  • douchi1945 2012-09-13 21:01
    关注

    jQuery

    $.get("SEARCH.php", {"_input" : $('input[name=input]').val() },
    function(returned_data) {
       $("input[name=output]").val( returned_data );
    }
    

    HTML

    input: <input type="text" name="input" value="" />
    output: <input type="text" name="output" />
    

    PHP Use echo instead of return since it looks that your code isn't in function:

    $input = $_GET['_input'];
    do some parsing of the input
    echo $result;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数