简体   繁体   English

如何在不使用表单操作的情况下获取文本框值并将其分配给PHP变量?

[英]How to get textbox value without using form action and assign it to a PHP variable?

I just want to ask a simple question. 我只想问一个简单的问题。 I am creating a validation form using PHP. 我正在使用PHP创建验证表单。 And what I need to do is to get the value of my textbox and assign it to a variable. 我需要做的是获取文本框的值并将其分配给变量。 Because I need that variable for comparing. 因为我需要那个变量进行比较。 But this process is done without an action form like GET or POST. 但是这个过程没有像GET或POST那样的动作形式。 How can I create a simple jquery for this? 我怎样才能为此创建一个简单的jquery?

Here's my sample flow. 这是我的样本流程。

<?php

    $data_qty = fn_product_qty($product_id);
    $x = //should be the textbox qty

    if($x != $data_qty){
       //some code here....
    }
?>
.....
<input type='text' name='qty' value='1' />

It can be done in javascript like, 它可以在javascript完成,

<script>
    var x='<?php echo $x;?>';
    $('button').on('click',function(){
        var qty=$('input[name="qty"]').val();
        if(x!=qty){
           alert('Both are not equal');
        }
    });
</script>

If you want in server side then use jquery ajax and php $_SESSION to compare both values. 如果你想在服务器端,那么使用jquery ajaxphp $_SESSION比较两个值。

You can use ajax to do this. 您可以使用ajax来执行此操作。 Can do alot of things, using jquery validation . 可以使用jquery验证做很多事情。 Usually when i used to compare username exists in my server-side db i extend a method from jquery validation. 通常当我用来比较用户名存在于我的服务器端db时,我会从jquery验证扩展一个方法。 Glad to post it here if u'd like 如果你愿意,很高兴在这里发布

   $.ajax({
                        url: "/Mycheckingaction",
                        type: 'POST',
                        dataType: 'json',
                        data: { id: $('input[name="qty"]').val(); },
                        success: function (response, textStatus, xhr) {
                                 if(!response)
                                 {
                                     alert('Error,not equal');     
                                 }
         });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过单击按钮(不提交表单)将Textbox值获取到同一php文件中的php变量? - How to get Textbox value to a php variable within same php file with a button click (without submitting the form)? 不使用表单将文本框值分配给php变量 - Assigning textbox value to php variable without using form 在没有表单操作的情况下获取php变量中的输入标签值 - get input tag value in php variable without form action 如何在没有post或get方法的情况下将html值分配给php变量 - how to assign the html value to the php variable without post or get method 如何在不使用 cookie 的情况下将 javascript 值分配给 php 变量 - How to assign javascript value to php variable without using cookie 如何在PHP的FORM ACTION中的循环中为ACTION赋值 - how to assign a value to ACTION in a loop in FORM ACTION in PHP 如何使用jquery获取textfield的值并将其分配给php变量 - How to get the value of textfield using jquery and assign it to php variable 使用PHP中的$ _GET方法为变量赋值 - Assign value to a variable using $_GET method in PHP 有没有一种方法可以转换文本框值并将其分配给php变量? - Is there a way to convert textbox value and assign to php variable? 如何在不提交表单的情况下将js变量赋值给php变量 - how to assign js variable to php variable without submitting the form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM