0

How to post an AJAX Request when a hidden input value change ?. The value in hidden input is always change because of Jquery autocomplete. I tried $("#id_pt_asal").change(function(event){ but nothing post on console log. is there any way how to do it ?

Here the HTML

<input type="hidden" name="id_pt_asal" id="id_pt_asal" value="" /> 

Here the AJAX script

$(document).ready(function() {
  $("#id_pt_asal").change(function(event) {
    var formData = {
      'id_pt_asal': $('input[name=id_pt_asal]').val()
    };

    $.ajax({
      type: 'POST',
      url: '<?=base_url()?>akademik/prodi_pindah',
      data: formData,
      dataType: 'json',
      encode: true
    })
    .done(function(data) {
      console.log(data);
      if (data.hasil_prodi == true) {
        $("#id_prodi_asal").html(data.html);
      }
    })

    event.preventDefault();
  });
});
31piy
  • 23,323
  • 6
  • 47
  • 67
Billy Adelphia
  • 1,007
  • 4
  • 19
  • 31

1 Answers1

0

First thing you need to get element of Jquery autocomplete. I assume your jquery autocomplete input given id is txt

$(document).ready(function(){
    $("#txt").on("keypress",function(){
        //$("#id_pt_asal").val($(this).val());
        $("#id_pt_asal").trigger('change');
    });
   $("#id_pt_asal").on("change",function(event){
     console.log(event);
    //ajax call
   });
});
Sovary
  • 692
  • 4
  • 11