[英]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 ajax
和php $_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.