在没有POST的情况下获取Textfield的值到PHP变量中

时间:2014-01-17 17:21:21

标签: php variables textfield

我需要获取文本字段的值并将其保存到变量中但没有提交按钮。

像这样: http://streambadge.com/

如您所见,您在第二步中编写的文本将自动添加到输出文本中。 我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

使用onchangeonkeyup来检测用户何时输入。

答案 1 :(得分:0)

您可以通过javascript / jquery(客户端站点脚本)来完成。

现场演示:
http://jsfiddle.net/5Y9mG/51/

HTML:

<input type="text" value="" id="country" />
<div  id="needs" >You will have output here :</div>

<强> Jquery的:

$( document ).ready(function() {
         $('input[id="country"]').on('keyup', function() {  // on keyup event in your input field
                $("#needs").append(this.value);// append values from input field
          });
    );

您希望将此值保存在php变量中,然后您需要ajax调用(无需提交表单),或者您需要提交表单。

对于基本的ajax,你可以读到这个:
http://www.tutorialspoint.com/jquery/ajax-jquery-post.htm

有用的jquery链接学习:
API文档:http://api.jquery.com/

基本:http://learn.jquery.com/about-jquery/how-jquery-works/