1

I want to execute the following:

$('#AccountID').change(SelectAccounts);

and then (SelectProducts)

Is there some way I can make the function SelectProducts execute after SelectAccounts all on the same line?

moey
  • 10,587
  • 25
  • 68
  • 112
Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427

3 Answers3

5

How about:

$("#AccountID").change(SelectAccounts).change(SelectProducts);

(in jQuery, event handlers are executed in the order they're bound. SelectAccounts will always run before SelectProducts)

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
1

Those are two different functions so you'd need to call them separately.

$('#AccountID').change(function () {
  SelectAccounts();
  SelectProducts();
});

In case you need to control the exact execution time for the second function, this discussion might be useful: Upon Link Click and setTimeout

Community
  • 1
  • 1
moey
  • 10,587
  • 25
  • 68
  • 112
0

use jQuery.Callbacks() added from jQuery v1.7

var callbacks = $.Callbacks();
callbacks.add( SelectAccounts);
callbacks.add( SelectProducts );
//then use callbacks.fire() with supported flags
xkeshav
  • 53,360
  • 44
  • 177
  • 245