K
kvnsmnsn
I've written the following Javascript file that includes an input text
field and an output text field, the latter of which is initialized to
zero. Each time the user enters a number in the input field and hits
the space bar, that number gets added to the value in the output field
and then the input field gets set to the empty string. The user can
enter as many numbers into the input field as s/he wants.
The problem I have with this is that even though I do set "sbInput" to
the empty string, somehow a space character ends up in it, so that if
I just type the number "123" into it, what actually ends up is " 123".
This doesn't affect the correct running of the web page, since a space
character doesn't change the numeric value of that field, but it's a
nuisance that I'd like to get rid of. Does anybody know how I can get
rid of this extra space character printing? Any information on this
would be appreciated.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Space Bug</title>
<script language="javascript">
function keyCheck ( evnt)
{
var theKey;
var sbIn = document.getElementById( "sbInput");
var sbOut = document.getElementById( "sbOutput");
if (!evnt)
{ evnt = window.event;
}
if (evnt.keyCode)
{ theKey = evnt.keyCode;
}
else if (evnt.which)
{ theKey = evnt.which
}
if (theKey == 32)
{ if (evnt.keyCode)
{ evnt.cancelBubble = true;
}
sbOut.value = Number( sbOut.value) + Number( sbIn.value);
sbIn.value = "";
}
}
</script>
</head>
<body>
<form name="sbForm">
<input type="text" name="sbInput" id="sbInput" size="5"
onkeypress="keyCheck( event);" />
<input type="text" name="sbOutput" id="sbOutput" size="5"
readonly="readonly" value="0" />
</form>
</body>
</html>
field and an output text field, the latter of which is initialized to
zero. Each time the user enters a number in the input field and hits
the space bar, that number gets added to the value in the output field
and then the input field gets set to the empty string. The user can
enter as many numbers into the input field as s/he wants.
The problem I have with this is that even though I do set "sbInput" to
the empty string, somehow a space character ends up in it, so that if
I just type the number "123" into it, what actually ends up is " 123".
This doesn't affect the correct running of the web page, since a space
character doesn't change the numeric value of that field, but it's a
nuisance that I'd like to get rid of. Does anybody know how I can get
rid of this extra space character printing? Any information on this
would be appreciated.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Space Bug</title>
<script language="javascript">
function keyCheck ( evnt)
{
var theKey;
var sbIn = document.getElementById( "sbInput");
var sbOut = document.getElementById( "sbOutput");
if (!evnt)
{ evnt = window.event;
}
if (evnt.keyCode)
{ theKey = evnt.keyCode;
}
else if (evnt.which)
{ theKey = evnt.which
}
if (theKey == 32)
{ if (evnt.keyCode)
{ evnt.cancelBubble = true;
}
sbOut.value = Number( sbOut.value) + Number( sbIn.value);
sbIn.value = "";
}
}
</script>
</head>
<body>
<form name="sbForm">
<input type="text" name="sbInput" id="sbInput" size="5"
onkeypress="keyCheck( event);" />
<input type="text" name="sbOutput" id="sbOutput" size="5"
readonly="readonly" value="0" />
</form>
</body>
</html>