Mohibur Rashid is correct. You called the function on Body Load and you are getting the
TextBox
value inside that. But the
TextBox
is blank when it is loaded for the first time.
So, either you can implement a
Button or handle the
Change
event of
TextBox
to do this.
Demo
[Issue] Image change on TextBox Change[
^]
Type "North" and press tab to see how image is changing.
One more thing. You have done one mistake in the function
whichDirection(x)
. You are getting the parameter
x
, but showing the variable
direction
, which is undefined.
So, below code is wrong...
document.write("You choose to go " + direction);
It should be...
document.write("You choose to go " + x);