Type something...


for the above textbox, I used the "onKeypress" function for the body tag, name of my function is keyPress........

<BODY onKeyPress = "keyPress()">

I globalized one variable - that I will use in a few functions.

var inString = ""

Here's the code:

function keyPress()
{
inString += String.fromCharCode(window.event.keyCode)
document.form1.Textbox.value = inString
}

IE has a fromCharCode() method -- to get the actual letter, number or symbol of the key

window.event.keyCode - gets us what key was pressed, saves it in the string and just adds it to the textbox, automatically, updating on another keypress.


<input type=submit onClick="checkKey()">



function checkKey()
{
if (window.event.keycode != 13) { // checks to see if return was pressed
alert("Your return key has been disabled");
return false
}
}

function onKeyPress () {
var keycode;
if (window.event) keycode = window.event.keyCode; -- quick browser check -- this for IE
else if (e) keycode = e.which; -- this works with Netscape
else return true; -- left over for all other browsers
if (keycode == 13) {
alert("Please Click on the Submit button to send this");
return false
}
return true
}
document.onkeypress = onKeyPress;

Modifiers:

returns a value when a mouse or keypress event occurs.

 

Alt = 1
control = 2
alt + control = 3
shift = 4
alt + shift = 5
control + shift = 6
alt + control + shift = 7

apple keys

meta = 8
meta + alt = 9
meta + control = 10
meta + alt + control = 11
meta + shift = 12
meta + alt + shift = 13
meta control + shift = 14
meta + alt + control + shift = 15