I looked at many of the similar questions, and I struggled to digest them - I'm taking my first math class that involves proofs, so I think my background was a bit weak.
The question: Suppose there is an injection f: A -> B. Prove there must exist a surjection g: B -> A.
My attempt:
Suppose there is an injection f: A -> B. By definition of injection, f($a_{1}$) = f($a_{2}$) -> $a_{1}$ = $a_{2}$.
Define a function g: B -> A, g(b) = a for all b$\in$B
g $\circ$ f (a) = f(g(a)) = a for all a$\in$A. This works because f is an injection, so f takes every element of A to a unique element of B. Further, the domain of g $\circ$ f is able to each every element of its co-domain. So g $\circ$ f is a surjection -> g is a surjection. Q.E.D.
Again I apologize that this question was answered in some form in the other questions - I'm operating on a simpler level than most, so I thought this question would still be of some benefit to others.
I don't follow your definition of $g$. Are you picking some element $a \in A$, then defining a constant function from $B$ to $A$, mapping every element of $B$ to this one element $a$? If so, this is (in general) not a surjection!
Here's the way I'd do it. Let $C$ be the range of $f$. Note that, if we restrict the codomain of $f$ to $C$, then $f$ is a surjection too, and hence invertible. Let $h : C \to A$ be this inverse. Note that $h$ is invertible too, and hence is surjective.
All we need to do is extend $h$ to map from all of $B$ to $A$. Note that since $h$ is surjective, all elements of $A$ are currently being mapped to, so the other points in $B$ can map to literally anywhere we want in $A$.
Choose some fixed $a_0 \in A$, and define $g : B \to A$ as follows: $$g(b) = \begin{cases} h(b) & \text{if } b \in C \\ a_0 & \text{if } b \notin C \end{cases}.$$ Then, if $a \in A$, then since $h$ is a surjection (since it is invertible), there exists some $b \in C$ such that $h(b) = a$. By definition, $g(b) = a$ too, hence $g$ is a surjection.