views:

36

answers:

1

I have an input field where the user enters an id#. I am using Ajax to check the database for that user's id# and afterwards populate the other input fields with that person's information from the database.

I am trying to run a series of validation statements after the information is inserted via Ajax into the input fields, but I can't figure out which event I need to use.

I am trying to do something like this:

$(.formfields).dataInserted(function() {
    if(costCenter == '') {
        $("#cost_center").after('<div id="cost_center_error" class="error">Your cost center number is required.</div>');
        hasError = true;
    }
}

I can't use keyup or change or anything like that, since there the user doesn't actually manually enter the data. What jQuery event type is it when Ajax inserts data into an input field?

+1  A: 

What jQuery event type is it when Ajax inserts data into an input field?

No event. Changing content from script does not fire any events(*). You must wire up your scripts to call you back when they've made a change.

If you really can't do that, you will need a poller interval to continually check the input for updates.

*: mostly. There are browser-specific hooks that you can use in some situations, but it's unpleasant and almost certainly better to fix the scripts to call you back instead. See this question for some discussion.

bobince