We have $3$ elements in set $B$ and $4$ elements in set $A$ and surjection means every element in $B$ must be mapped to. So, this problem reduces to distributing $4$ distinct elements $(r = 4)$ among $3$ distinct bins $(n = 3)$ such that no bin is empty, which is given by $n! S(r, n),$ where $S(r, n)$ is Stirling's number of 2nd kind. So, here we need $S(4, 3).$
We have $S(r+1, n) = n* S(r, n) + S(r, n-1)$
So, Stirling numbers of second kind can be generated as follows:
$1$
$1\quad1$
$1\quad 3\quad 1$
$1\quad 7\quad 6\quad 1$
So, $S(4,3) = 6$ and $3! = 6$ giving, number of surjective functions $= 6*6 = 36.$
Ref: See Theorem 9:
http://www.cse.iitm.ac.in/~theory/tcslab/mfcs98page/mfcshtml/notes1/partset.html
Alternative approach ,
Answer is $36.$
For onto function from a set A(m-element) to a set B(n-element), $m \geq n.$
Number of onto function $= n^m - ^nC_1(n-1)^m + ^nC_2(n-2)^m - ^nC_3(n-3)^m+\ldots +^nC_n(n-n)^m$
$(+,- $ alternative$)$
$$\bf{=\sum_{i=0}^n (-1)^i \;nC_i\;(n-i)^m}$$
Here $m=4$ and $n=3 $
So, number of onto functions
$\quad \quad = 3^4 - ^3C_1(3-1)^4 + ^3C_2(3-2)^4 - ^3C_3(3-3)^4$
$\quad \quad = 81 - 3*16 +3*1 - 1*0$
$\quad \quad = 36.$
ref@ http://www.cse.iitd.ac.in/~mittal/stirling.html