This question has been asked a long time ago, but the accepted answer is not as general as it could be, so I add a proof here for future readers.
A function $f : X \to Y$ where $X$ is a topological space and $Y$ is a set is called locally constant if every point $x \in X$ admits a neighborhood $U$ where $f|_U$ is constant. An equivalent way to state this is that $f$ is continuous when $Y$ is equipped with the discrete topology ; saying that every point admits a neighborhood where the function is constant is equivalent to saying that $f^{-1}(f(x))$ is open for every $x \in X$.
So suppose $X$ connected. Then for $y \in Y$, $f^{-1}(y)$ is open, and it is also closed since $X \backslash f^{-1}(y) = f^{-1}(Y \backslash \{y\}) = \bigcup_{z \in Y \backslash\{y\} } f^{-1}(z)$ is a union of open sets in $X$. Since it is clopen and $X$ is connected, $f^{-1}(f(x)) = X$ for any $x \in X$, that is, $f$ is constant.
In particular, a locally constant function $f : X \to Y$ is a function which is constant on the connected components of $X$, since the restriction of a locally constant function to a subspace is locally constant (use the fact that inclusion maps are continuous and use the topological definition of locally constant given above). Note however that the connected components need not be one of those neighborhoods where the function is constant as in the original definition, since they are not necessarily open.
To know exactly on what open sets $f$ has to be constant, consider the following equivalence relation : for $x,y \in X$, we write $x \equiv y$ if and only if there exists a connected subset $C \subseteq X$ with $x,y \in C$. Since the intersection of two connected subsets with non-empty intersection is connected, $\equiv$ is an equivalence relation whose partition of $X$ gives the connected components of $X$. Consider the space $X/\equiv$ of equivalence classes, i.e. we collapsed each connected component to a point ; equip $X/\equiv$ with the quotient topology. Then a locally constant function $f : X \to Y$ (i.e. a continuous map with $Y$ discretE), being constant on connected components, factors through a continuous map $\widetilde f : X/\equiv \to Y$. Since in $X/\equiv$, the connected components are points (we say that $X/\equiv$ is totally disconnected), but the topology on $X/\equiv$ might not be trivial ; a locally constant function $f$ is precisely one for which $\widetilde f$ is continuous, i.e. for every $[x] \in X/\equiv$, $f$ is constant on $\pi^{-1}(U)$ for some open neighborhood $U$ of $[x]$ in $X/\equiv$.
Think of a locally constant function on $\mathbb Q$ (with the subspace topology from the reals). Even though the connected components are points, not every function on $\mathbb Q$ is locally constant.
Hope that helps,