slimflem
11-01-2004, 08:40 PM
Hi.
This would appear to be easy, and I want to make sure I am doing it correctly. I allow the user to press the spacebar to perform an action in addition to a button. When they press the spacebar, I want to disable the onKeyUp event for document.body so the user cannot machine gun the spacebar and cause stuff to happen I don't want to. What I'm doing is setting document.body.onkeyup = null when the spacebar press is captured and reenabling it after the action is complete. Here's my code:
<SCRIPT LANGUAGE="JavaScript">
function captureFKey()
{
document.body.onkeyup = null;
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
/*
* Spacebar = Print Label
*/
if (keycode == 32)
{
printLabel();
return false;
}
else
return true;
}
function printLabel()
{
document.getElementById("cmdPrintLabel").disabled = true;
document.Form1.submit();
document.body.onkeyup = "return captureFKey()";
}
</SCRIPT>
<body onkeyup="return captureFKey()">
Does this seem to be the correct way to do this? If there are better ways, please let me know.
Thanks.
This would appear to be easy, and I want to make sure I am doing it correctly. I allow the user to press the spacebar to perform an action in addition to a button. When they press the spacebar, I want to disable the onKeyUp event for document.body so the user cannot machine gun the spacebar and cause stuff to happen I don't want to. What I'm doing is setting document.body.onkeyup = null when the spacebar press is captured and reenabling it after the action is complete. Here's my code:
<SCRIPT LANGUAGE="JavaScript">
function captureFKey()
{
document.body.onkeyup = null;
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
/*
* Spacebar = Print Label
*/
if (keycode == 32)
{
printLabel();
return false;
}
else
return true;
}
function printLabel()
{
document.getElementById("cmdPrintLabel").disabled = true;
document.Form1.submit();
document.body.onkeyup = "return captureFKey()";
}
</SCRIPT>
<body onkeyup="return captureFKey()">
Does this seem to be the correct way to do this? If there are better ways, please let me know.
Thanks.