0

i thought i had solved this but my basic example seems to not be working. not sure why but i am sure it is a small issue. any help is appreciated.

<html>
<head>
</head>

<body>
<textarea rows="20" cols="61" id="entry" name="entry" class="body_text" wrap="physical">
</textarea>
</body>
</html>
<script>
function keypress(e){
var key_s = (window.event) ? event.keyCode : e.keyCode;
document.getElementById("entry").innerHTML=key_s;
}
</script>

4
  • That's not how you format HTML for Stackoverflow. All you have to do is indent it all by 4 or more spaces. Commented Aug 24, 2010 at 12:29
  • thanks will keep this in mind for next post. Commented Aug 24, 2010 at 12:30
  • was unaware of this feature. thank you for pointing it out, definitely will do so going forward. Commented Aug 24, 2010 at 15:07
  • I actually like this formatting. This definitely doesn't deserve a downvote. +1 to even it out Commented Aug 31, 2010 at 19:51

1 Answer 1

1

You should add the keypress event listener to the browser. That can be done in several ways:

  • rename keypress to onkeypress (-> window.onkeypress)
  • use addEventListener or attachEvent (IE specific):

    if(window.addEventListener) window.addEventListener('keypress', keypress, false); else if(window.attachEvent) window.attachEvent('onkeypress', keypress); else window.onkeypress = keypress;

What's happening? First, check if the standard way to handle events is available. If so, use it. Otherwise, use Internet Explorers method. If you're really using an old browser, use a legacy method.

You should also use 'value' instead of 'innerHTML' on textarea's.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.