Reputation: 7520
I just want to ask a simple question. I am creating a validation form using 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. How can I create a simple jquery for this?
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' />
Upvotes: 0
Views: 804
Reputation: 409
You can use ajax to do this. Can do alot of things, using jquery validation. Usually when i used to compare username exists in my server-side db i extend a method from jquery validation. 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');
}
});
Upvotes: 1
Reputation: 40639
It can be done in javascript
like,
<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.
Upvotes: 1