Let $f: \mathbb{R} \to \mathbb{R}$ be the function defined by $f(x) = x^2$ (as in your example, such that $ A = B = $ the set of real numbers $\mathbb{R}$).
The reason why, in this case, $f(x)$ is not onto $\mathbb{R}$ is because there exists (infinitely many) values in $\mathbb{R}$ (specifically all negative real numbers) for which there IS NO $x \in \mathbb{R}$ such that $f(x)=x^2 < 0$. For example, consider the real number $-4$; is there any real number $x$ such that $f(x)= x^2 = -4$?
No.
So $f(x) = x^2$ is not onto $\mathbb{R}$. (It also is not one-to-one).
Can you think of other examples of functions that are not onto?
Here's another example: let $g: \mathbb{N} \to \mathbb{N}$ with $g(x) = 2x$.
So the domain of g is all natural numbers: $\{1, 2, 3, 4, ...\}$. But the range (or rather image) of $g$ is only those numbers in $\mathbb{N}$ that are even: $\{2, 4, 6, 8, ...\}$. So for any odd number in $\mathbb{N}$, say 3, e.g. has an $x \in \mathbb{N}$ such that $g(x) = 2x = 3$.
Note that a function may not be onto one particular range, but can be onto another particular range. In the first example, above, if we let $\mathbb{R^*}$ denote the set of all non-negative real numbers, then $f: \mathbb{R} \to \mathbb{R^*}$, with $f(x) = x^2$, then $f(x)$ is onto $\mathbb{R^*}$. Can you see why? And in the second example, if we define $g: \mathbb{Q} \to \mathbb{Q}$, then $g(x) = 2x$ is indeed onto $\mathbb{Q}$.