[Javascript] Is there a way to capture the key stroke and...

Peter Brunone peter at brunone.com
Mon Jul 15 23:23:58 CDT 2002


	Like this?  It only works in IE, but it should do what you need.

<SCRIPT LANGUAGE="JavaScript">
function fnTrapKD(){ // check box and try to type in oExample field
   if(oTrap.checked){
      oOutput.innerText+="[trap = " + event.keyCode + "]";
      event.returnValue=false;
   }
   else{
      oOutput.innerText+=String.fromCharCode(event.keyCode);
   }
}
</SCRIPT>
<INPUT TYPE="checkbox" ID="oTrap">
<INPUT ID="oExample" TYPE="text" onkeypress="fnTrapKD()">
<TEXTAREA ID="oOutput" ROWS="10" COLS="50">
</TEXTAREA>


|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of Scott.Wiseman
|
|not have it output to the field...
|just get rid of the keystroke
|
|I guess trap it..
|
|
|function checkit()
|{
|
|
|  var keycode;
|if (window.event) keycode = window.event.keyCode;
|else if (e) keycode = e.which;
|else return true;
|
|
|if (keycode == 13)
|   {
|        
|    add_data();
|  
|   return false;
|   }
|   
|if  (keycode ==43)
|   {
|   
|        window.document.myform.gcc.value=''; alert('zerod out ggc value');
|        
|        document.myform.AssociateName.selectedIndex =
|document.myform.AssociateName.selectedIndex + 1  ;
|         if(document.myform.AssociateName.selectedIndex<0)
|     {
|         alert("No more associates..Starting at the first one");
|         document.myform.AssociateName.selectedIndex =1;
|     }    
|     
|        
| 
|getCommissionsByRecordnumber(document.myform.AssociateName.selectedIndex,
|window.document.myform.gcc); 
|
|        return false;
|   }
|   
|   
|else
|{
|
|   return true;
|}   
|   
|}
|



More information about the Javascript mailing list