How to detect change in input value with active readonly

Asked

Viewed 548 times

0

HTML:

<!-- Campo preenchido com retorno AJAX -->
<input type="text" name="estado-cliente" hidden id="estado-cliente"  readonly="readonly"/>

How do I stop detecting any change in value?

Note: the value is added and changed via JS

Unsuccessful with the excerpt below:

$("#estado-cliente").bind("change paste keyup", function() {});

2 answers

0

Add in your Javascript the following

$("#estado-cliente').on('change', function () {
  alert("Estão tentando alterar");
});

0

Try to put this jQuery to run at the beginning of the page:

$(document).ready(function () {   
   $('input#estado-cliente').bind("change", function () {
      alert($(this).val());
   });
});

If you need to simulate the exchange of values:

$('#estado-cliente').val('teste').change();
// Senão funcionar da forma acima tente assim
$('#estado-cliente').val('teste').trigger('change');
  • Hello @n3uRoQuiLa, the first option did not understand how to check and auto-execute the function based on the value change, the second failed. My doubt can be better illustrated if you understand something like: "detect the change of value by the console..."

  • I made some adjustments, now that I saw that the input is Hidden. Try this way...

  • Would you like to continue this discussion via chat? http://chat.stackexchange.com/rooms/54841/como-detectar-alteracao-no-value-do-input-com-readonly-ativo

Browser other questions tagged

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