p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   ie7 keycode, event handlers (http://p2p.wrox.com/showthread.php?t=50729)

erobb November 24th, 2006 01:37 PM

ie7 keycode, event handlers
I have a peice of code that I am using to stop the enter key (return) from submitting a form. I wanted to make a modification to this code so that users were not allowed to paste elements into a form. Because its a time entry form I am using on keydown ect to auto calculate totals and cnrl-v stops my function from being fired.

The Nav branch of the code works great in FF but I cant get it working in ie 7. Since I cant revert to ie 6 to see if its specific to 7 Im not sure if the handler is not firing because of the new version or my logic is just wrong for ie.

I know people will still be able to go edit>paste but because of the nature of the form I think it will not be an issue as it will certainly be quicker to enter 8 numbers than do edit>paste 8 times

function kH(e) { //function is not called in IE when a control - v combination is used
    var nav = window.Event ? true : false;
    var pK = document.all? window.event.keyCode:e.which;

        if(e.ctrlKey == true){
            return false;
        if(e.target.type != 'textarea'){
            return pK != 13;

        alert(event.ctrlKey + 'hello');
        if(event.ctrlKey == true){
            return false;
            return pK != 13;

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);

Thanks Earl

All times are GMT -4. The time now is 05:35 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.