View Full Version : onkey* events not working under IE7?

Mar 5th, 2007, 06:05 PM
hello, I am trying to detect if the Enter key is pressed in a textArea. SImple enough it seems although IE 6 + 7 are not detecting anything, FF works great.

here is the code I have on my textArea field.

<textarea id="BottomText" name="BottomText" rows="5" cols="85" onkeypress="alert('pressed');if(event.keyCode==13){alert('You pressed enter');return false}"><%=BotText%></textarea>

Any thoughts? I have tried onkeyup, onkeydown, etc but nothing in IE?

any help would be excellent, thanks CF! :thumbsup:

Mar 5th, 2007, 06:24 PM
It works for me in IE6. But if you don't want newlines, why don't you use textbox instead of textarea?

Mar 5th, 2007, 07:08 PM
Do you mean why don't I use a <input type=text /> ?? I don't use that because I require a large number of characters.

I am saving the field to SQL to later be consumed by Flash. And since it doesn't appear that anything (ie . <br> ) is being saved into the field (just shows up as a space) when 'Return/Enter' is pressed then I guess the only way to disallow it is by the onkeypress() -- unless you have any other ideas?


Mar 5th, 2007, 07:20 PM
You can also have a lot of characters in a textbox. But you should be able to save the data with newlines in SQL. It may show up as a 'square' in the table column but you can display it in the page with newlines even without replacing newlines with <br>s by putting the text inside the <pre> </pre> tags.