kowsalya v
kowsalya v

Reputation: 41

How to know input values changed in jQuery

I have worked in filter option. Here more than one input fields are there. Like one select, input text, button click. All are under one class named "filter-option". When any one of these modified I have to alert the value inside a jQuery.

I have tried below code but not working.

$("body").on('DOMSubtreeModified', "filter-option", function() {
    alert('changed');
});

Upvotes: 0

Views: 85

Answers (3)

Yadukrishnan M
Yadukrishnan M

Reputation: 162

I think the best way is to store a flag in data-attribute of your form.

$(document).on("change", "#your_form_id :input", function () {
$("#your_form_id").data("changed", true);
alert("changed");
});

It will invoke change event of all the input fields inside the form tag.

Upvotes: 0

Manjuboyz
Manjuboyz

Reputation: 7066

You can use Keyup function.

Keyup

<script type="text/javascript">
 $(document).ready(function () {
   $('#SelectorName').keyup(function () { alert('text changed'); });
 });
</script>

OR using keypress

keypress

<input type="text">

Jquery

$(document).ready(function(){
  $("input").keypress(function(){
  alert("clicked");
  });
});

OR using blur().

blur

blur gives you the change event only when you click on something else post entering the value in the input field.

function yourFunction() {
  alert("clicked");
}
<input type="text" id="fname" onblur="yourFunction()">

Upvotes: 0

Jeni
Jeni

Reputation: 430

If you want the event to be fired whenever something is changed within the element then you could use the change, keyup, blur events.

$("body").on('change keyup blur', "filter-option", function() {
   alert('changed');
});

see also: Detecting input change in jQuery?

Upvotes: 1

Related Questions