Br0therBrigham Br0therBrigham -4 years ago 68
Javascript Question

text box that allows computer to recognize letter in the order they appear

I am a fairly new programmer and I am programming a encrypt-er.

so what I need is a text-box that allows the viewer to type the plain text and have the computer recognize which letter came first, second, third, ext......

for example if a viewer typed "test" in the text box. I would need a way for the computer to recognize that "t" came first and distinguish it from the other letters in some way.

what is the best way to do this.

here is the code I have so far

function Encode() {

var myNewEncode = document.getElementById('myTextField').value;
if (myNewEncode.length >= 20) {
alert('text is limeted to 20 charictors');
return;
}

var Encode = document.getElementById('Encode');
Encode.innerHTML = myNewEncode;

}

})

Answer Source

in jQuery:

 $(function() {
        $('#mytext').keypress(function(evnt) {
               console.log(evnt.key)
         });
     })

in javascript:

document.getElementById("myField").addEventListener("keypress",function(evnt){
            console.log(evnt.key);
  })

You can try this code it will solve your problem. mytext is your input text box. Each time you type in a character it will evnt.key will return that particular character.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download