Reputation: 9084
I am having jquery as follows,
$(document).on('click', '.save_button', function (e) {
var amount = $('.actual_pay').val();
});
Which means when a user clicks the button with class save_button
, the script executes and sets the value of the var amount
to the value of the field with class actual_pay
.
Up to this no problems and it is working fine, but the input box with class name actual_pay
is editable and any time the value can be changed, I have to detect the changed value of the input box, for which i have tried with
var amount = $('.actual_pay').val().change();
But it is showing error:
.change is not a function.
How to detect the change happening to the class actual_pay
and to store the changed value to the amount variable?
Upvotes: 2
Views: 140
Reputation: 36703
You can attach an input
event listener.
var amount;
$('.actual_pay').on("input", function(){
console.log("Something is changed in actual_pay");
amount = $(this).val(); // save val
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="actual_pay">
Actions which invoke input events are
Upvotes: 2
Reputation: 304
You can get value of that input box with this function:
$( "input.actual_pay" ).keyup(function() {
var amount = $(this).val();
});
If you are changing that input manually, you will use 'keyup', otherwise you should use
$( "input.actual_pay" ).change(function() {
var amount = $(this).val();
});
Upvotes: -1
Reputation: 3531
$('.actual_pay').val().change();
won't work because this is wrong approach. You can do by following method
$('.actual_pay').on('input',function(){
alert('Something Modified');
});
Upvotes: 0