Proving a function is onto and one to one
Solution 1:
Yes, your understanding of a one-to-one function is correct.
A function is onto if and only if for every $y$ in the codomain, there is an $x$ in the domain such that $f(x) = y$.
So in the example you give, $f:\mathbb R \to \mathbb R,\quad f(x) = 5x+2$, the domain and codomain are the same set: $\mathbb R.\;$ Since, for every real number $y\in \mathbb R,\,$ there is an $\,x\in \mathbb R\,$ such that $f(x) = y$, the function is onto. The example you include shows an explicit way to determine which $x$ maps to a particular $y$, by solving for $x$ in terms of $y.$ That way, we can pick any $y$, solve for $f'(y) = x$, and know the value of $x$ which the original function maps to that $y$.
Side note:
Note that $f'(y) = f^{-1}(x)$ when we swap variables. We are guaranteed that every function $f$ that is onto and one-to-one has an inverse $f^{-1}$, a function such that $f(f^{-1}(x)) = f^{-1}(f(x)) = x$.
Solution 2:
A function $f:A\rightarrow B$ is one-to-one if whenever $f(x)=f(y)$, where $x,y \in A$, then $x=y$. So, assume that $f(x)=f(y)$ where $x,y \in A$, and from this assumption deduce that $x=y$.
A function $f: A\rightarrow B$ is onto if every element of the codomain $B$ is the image of some element of $A$. Let $y\in B$. We can show that there exists $x\in A$ such that $f(x)=y$. Choose $x=f^{-1}(y)$ and so $f(f^{-1}(y))=y$. So for all $y\in B$, there exists an $x\in A$ such that $f(x)=y$.