J
jhoff
I'm trying to use javascript to execute code when the enter key is
pressed in a text box.
Basically, I'm doing this...
<html>
<body onload="load()" onunload="GUnload()">
<form name=zipform>
<input type="text" name="zipcode" value="" size="5"
class="flat">
<input type="button" name="button" value="Click"
onClick="changezip(this.form.zipcode.value);">
</form>
</body>
<script type="text/javascript">
function checkCR(evt)
{
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text") &&
(node.value.length==5))
{
changezip(this.form.zipcode.value);
}
else if ((evt.keyCode == 13) && (node.type=="text"))
{
return false;
}
}
document.onkeypress = checkCR;
function changezip(zip)
{
//Code that changes zipcode goes here
}
</script>
</html>
I DO NOT want to reload the page ( I.E. post the contents ) when the
enter key is pressed. In the case i've created, pressing the "click"
button after entering a zipcode, executes the javascript function
"changezip", however pressing enter will reload the page, and tack the
"?zipcode=xxxxx" to the end of the url...
Please help!
Thanks,
JHoff
pressed in a text box.
Basically, I'm doing this...
<html>
<body onload="load()" onunload="GUnload()">
<form name=zipform>
<input type="text" name="zipcode" value="" size="5"
class="flat">
<input type="button" name="button" value="Click"
onClick="changezip(this.form.zipcode.value);">
</form>
</body>
<script type="text/javascript">
function checkCR(evt)
{
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text") &&
(node.value.length==5))
{
changezip(this.form.zipcode.value);
}
else if ((evt.keyCode == 13) && (node.type=="text"))
{
return false;
}
}
document.onkeypress = checkCR;
function changezip(zip)
{
//Code that changes zipcode goes here
}
</script>
</html>
I DO NOT want to reload the page ( I.E. post the contents ) when the
enter key is pressed. In the case i've created, pressing the "click"
button after entering a zipcode, executes the javascript function
"changezip", however pressing enter will reload the page, and tack the
"?zipcode=xxxxx" to the end of the url...
Please help!
Thanks,
JHoff