View Single Post
  #1 (permalink)  
Old November 24th, 2006, 01:37 PM
erobb erobb is offline
Authorized User
 
Join Date: Jun 2003
Location: Richmond, VA, USA.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default 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(nav){
        if(e.ctrlKey == true){
            return false;
        }
        if(e.target.type != 'textarea'){
            return pK != 13;
        }
    }else{
        alert('win');

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

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

Thanks Earl
www.jhdesigninc.com

Reply With Quote