views:

66

answers:

1

I don't want to have a formal form field but save every user input directly into a variable and append new letters to a field every time the user enters a new letter. What command do I need?

A: 
window.onkeypress = function(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);
    document.body.innerHTML += character;
};
Luca Matteis