checks if the input value has changed with jQuery

Asked

Viewed 337 times

2

I need to identify if the value of a input changed with jQuery. I’m trying to do so:

$('input[name=cliente]').on('keyup', function(e) {
  // Aqui vou por minhas funções
 }

But it’s not working. Dude input is named after cliente.

1 answer

2


I usually put in a variable "outside", and "inside" of the event I check it.

var textoCliente = '';
$('input[name=cliente]').on('keyup', function(e) {
    var textoAtualizado = $(this).val();
    if( textoAtualizado != textoCliente ){
        // Aqui vou por minhas funções
    }
    textoCliente = textoAtualizado;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.