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条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器