Click to See Complete Forum and Search --> : why this script is not working


mashraf
06-23-2003, 10:57 AM
Hi,
I want to take some action when user presses any key other
than arrow and pageup and page down. This script is suppose to
do the job, if I am not wrong.

Why it is not working. Please take a look.

Thanks,
Mashraf

<script type="text/javascript">
function keyUP(e){
var trigger = (document.all)?event:e;
keyValue = String.fromCharCode(trigger.keyCode);
if (trigger.keyCode <= 32 && trigger.keyCode >= 41)
{
alert(keyValue+" was pressed")
}

}

if(!document.all){
document.captureEvents(Event.KEYUP);
}
document.onkeyup = keyUP;
</script>

Khalid Ali
06-23-2003, 02:04 PM
Main error in your code was that your if statement was logically wrong..A number can not be at same tim elower then 32 and upper then 41 it had to be
either lower or upper..

below is the fixed function of yours

function keyUP(e){
var trigger = (document.all)?event:e;
var keyValue = parseInt(trigger.keyCode);
if (keyValue <= 32 || keyValue >= 41) {
alert(keyValue+" was pressed")
}
}

mashraf
06-23-2003, 02:37 PM
Thank you very much khalid. Your are great.

Mashraf

Khalid Ali
06-23-2003, 04:47 PM
:D

You are welcome