0

I want to do search and it can search many times. when it is submitted, it will show value in textbox by using document.getelementById("").value. All work well but I added ajax for filter search, document.getelementById("").value couldn't work.

        $(document).ready(function() {
            $('#job_no').change(function() {
                $.ajax({
                    type: 'POST',
                    data: {JOB_NO: $(this).val()},
                    url: 'select.php',
                    success: function(data) {
                        $('#input_na').html(data);
                    }
                });
                return false;
            });
        });

<script type="text/javascript">document.getElementById('input_na').value = "<?php echo $_POST['input_na'];?>";</script>

phuzi
  • 12,078
  • 3
  • 26
  • 50
  • see console for any possible errors – Shubham Dixit May 15 '19 at 07:26
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – phuzi May 15 '19 at 07:26

1 Answers1

0

Try this:

$(document).ready(function() {
  $('#job_no').change(function() {
    var $this = $(this); //add this line
    $.ajax({
      type: 'POST',
      data: {JOB_NO: $this.val()}, //change this line
      url: 'select.php',
      success: function(data) {
        $('#input_na').html(data);
      }
    });
    return false;
  });
});

the 'this' in $.ajax(..) function will not refer to $('#job_no'), so it should be assigned to another variable "$this" for use inside the ajax function.

djolf
  • 1,196
  • 6
  • 18