Hypotheses on the Intermediate Value Theorem

Background A typical statement of the Intermediate Value Theorem given in elementary analysis, this particular one lifted from Wikipedia, goes as follows:

If $f$ is a real-valued continuous function on the interval $[a,b]$ and $u$ is a number between $f(a)$ and $f(b)$ then there exists a number $c \in [a,b]$ such that f(c) = u

This statement would lead one to believe that the result is somehow related to the compactness of $[a,b]$. However, it is a theorem of general topology that if $f$ is a real-valued continuous function defined on a connected space $X$ then it takes on every value between $f(p)$ and $f(q)$ for every $p,q \in X$. Even more generally, we have that since continuous maps preserve connectivity, $g(X)$ is connected for any continuous map $g$ defined on $X$ to some other topological space $Y$.

In fact, the first more specialized version follows almost immediately from the topological version, taking into account the fact that a subset of $\mathbb{R}$ is connected if and only if it is an interval.

Question Is there a reason why we cannot state the first theorem more generally as:

If $f$ is a real-valued continuous function on an interval $J \subset \mathbb{R}$, $a,b \in J$ and $u$ is a number between $f(a)$ and $f(b)$ then there exists a number $c \in J$ such that f(c) = u

-
Well, you want $a$ and $b$ in the interval. – Mark Feb 14 '12 at 21:26
no there is a problem you can see Introduction to real analysis by Bartle page 133 – user24993 Feb 14 '12 at 21:37
And when $a$ and $b$ are in the interval, you can restrict your attention to the closed interval having those two as end points, and so you're back to the original formulation. – Harald Hanche-Olsen Feb 14 '12 at 21:45
Ok, I see; so, the point is both $a$ and $b$ must be in the interval to begin with (which, of course makes sense) and therefore one might as well consider the (closed) interval $[a,b]$ (as opposed to some open interval $(a_0, b_0)$ where $a_0 \leq a < b \leq b_0$ – ItsNotObvious Feb 14 '12 at 22:07
@3Sphere: Indeed. – Mark Feb 14 '12 at 23:23

Take $f(x) =x$ for $x\in(0,1]$ and $f(0) =-1$. Then $f$ is continuous on $J = (0,1)$ in the subspace topology, but for $u = -0.5$ there is no $c$ such that $f(c) = u$.
@HaraldHanche-Olsen: I didn't say that the definition OP has in mind is incorrect (by the way, there was no "$a,b\in J$" part when I've answered). I just pointed out the possible problem related to this definition since it was unclear if $a,b\in J$ or not. – Ilya Feb 15 '12 at 8:52