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,197
  • 23
  • 67
  • 110
Samantha J T Star
  • 28,982
  • 82
  • 233
  • 406

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
  • 121,982
  • 31
  • 284
  • 303
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,197
  • 23
  • 67
  • 110
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
diEcho
  • 52,196
  • 40
  • 166
  • 239