Hello, I would like to know if there is any method in jQuery that returns whether there were changes to the initial form or not. For example, I have 3 empty fields, and so I modify one of them. jQuery return something to me ...
Thank you.
Hello, I would like to know if there is any method in jQuery that returns whether there were changes to the initial form or not. For example, I have 3 empty fields, and so I modify one of them. jQuery return something to me ...
Thank you.
You do not need jQuery.
document.getElementById('campo').addEventListener('input', function () {
/* faz alguma coisa */
});
You can use change
instead of input
if you want your code to run only when the user exits the field.
If you want to do this for everyone, you can do
var toArray = Array.prototype.slice.call;
function doSomething() {
/* faz alguma coisa */
}
toArray(document.querySelectorAll('input[type="text"]')).forEach(function (input) {
input.addEventListener('input', doSomething);
});
You can also use the jQuery change function, it looks like this:
$(':input').change(function(){
//Ação desejada.
});
In this small example I checked to select all the INPUT fields, but you can select the desired fields from the jQuery selector.
In Desired Action, you place the code to be executed when a user modifies the selected field, such as giving feedback that the field has been filled in.