let set s={1,2,3,4}
now see mapping from s to s
for f to be onto every element of codomain must be mapped by every element in domain.
since cardinality is same for both domain and codomain. we can not have mapping like f(1)=1 & f(2)=1 if it happened then at least one element remain umapped in codomain,which resultant f not to be onto but it is given that f is onto.so every element in codomain have exactly one element in domain.so one of mapping be like f(1)=2, f(2)=3,f(3)=4,f(4)=1 which certainly prove that f is an one one function also.
NOTE:if s is infinite then this result may not always be true.