1

I have a 2 textboxes. In the first I type an unique id for a customer. When I tab out of this textbox it fires a query to my DB and fills the second textbox, which is the customer type.

When the value of the second textbox is updated from the DB (i.e. the value 'changes' from "" to the retrieved value) I want to grab that value and send it as a parameter to my second DB query.

I don't always know how long the first query takes to update the second textbox, so I want to perform the query once the value in the second textbox changes.

Looking at the jQuery .change() event, it appears it only fires when the textbox loses focus, yet in my design, the textbox never gains focus.

Ideally it would be great if I could detect when the second textbox value changes and then fire my 2nd query.

How is this possible?

Thanks! Mark

1
  • 1
    Why do you want to retrieve the value you just sent via AJAX? Couldn't you continue your function in javascript when you change the value. Or, even further, do the complete PHP first before sending it back and forth so many times? Commented Jan 20, 2011 at 14:55

2 Answers 2

1

I'm not sure exactly what your Ajax call looks like, but you should be able to use trigger('change'), or simply change(), to trigger the change event-handling:

$('#input2').val(variableFromAjaxFunction).trigger('change');
Sign up to request clarification or add additional context in comments.

Comments

0

In the callback for your first AJAX request (where you populate the second textbox), trigger the change event.

You'll probably have:

jQuery.ajax({
  ...
  success: function (response) {
      $('#textbox2').val(response);
  }
});

Just change it to:

jQuery.ajax({
  ...
  success: function (response) {
      $('#textbox2').val(response).trigger('change');
  }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.