dongtaochan0777 2014-05-23 03:49
浏览 38
已采纳

在写入输入类型文本之后存储PHP变量

I need to save the value of a input type text in a PHP variable as soon as the user writes it. I found that the blur event in JQuery can trigger an event that happens after writing to the input type text, so I have the following:

<script>
     $("document").ready( function() 
     { 
       $("#primerApellido").blur(function() {
            alert('out');
            <?php 
                $primerApellidoForm = 
                "<script type=\'text/javascript\'>
                    $('#primerApellido').val();
                </script>
                ";
            ?>                
        });
     }); 
 </script>

And here is my input type text:

<input type="text" id="primerApellido" name="primerApellido" value="<?php echo $primerApellidoForm?>"/>

So as you can see, I need to save what is typed on the input on the PHP variable as soon as the user leave the text box. Right now it save literally the Javascript variable assignation, not the value that I need.

How can I assing the typed value on the text box to my PHP variable?

  • 写回答

5条回答 默认 最新

  • dongyong8098 2014-05-25 20:57
    关注

    I followed the advice from Mark Carpenter to use Ajax function, below is the code that do what I want:

    $("document").ready( function() 
    $("#primerApellido").blur(function() {
        $.ajax({
        type: "GET",
            url: "destinationURL.php",
            data: "primerApellidoForm="+$('#primerApellido').val(),
            success: function(msg){
                alert( "Data Saved: "+msg);
             }
          });
    
       });
    });
    

    Now the PHP variable "primerApellidoForm" have the value from $('#primerApellido').val() input type.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导