Clearly if |S| < |T| there are no onto functions at all. And if |S| = |T| there are |S|! onto functions.
In the remaining cases I think I'd do this by subtracting from the total number of functions from S to T the number of functions that aren't onto. For example suppose |T| = 3. Lets denote the number of onto functions from a set of size m onto a set of size n by F(m,n)
Then there are 3^|S| functions in total, and the functions that aren't onto take either 1 or 2 values from T. There are 3 choose 1 = 3 subsets of size 1 of T so there are 3*F(|S|,1) functions that take 1 value. Similarly there are 3 choose 2 = 3 subsets of size 2 of T, so that there are 3*F(|S|,2) functions that take exactly 2 values from T. So you could build up a recursive calculation of the number of onto functions from |S| to |T| in this hard case.
It's likely that the numbers you get are some well-known combinatorial function of two numbers such as something to do with the Catalan numbers , so that there might be some closed form formula, but I don't know.