I guess because a text area implies multiple lines of text, and the user may well press the enter key inadvertantly at the end of a line or deliberately to create a new paragraph. If that causes the form to submit prematurely he may well be annoyed.
A textbox has only one line and if the user presses enter it is most likely that he has finished his entry.
The Following 2 Users Say Thank You to Philip M For This Useful Post:
Except that this function is for a chat, so NOT being able to press enter is annoying.. using a textbox is too small, and you lose track of what your writing... textarea is bigger and it wraps.. i just need it to be able to press enter.. now, i tried that site and it submitted when i pressed enter, except nothing happened.. it was as though no variables were passed or something...
function enter(evt)
{
var charCode = (evt.which) ? evt.which : window.event.keyCode;
if (charCode == 13)
{
document.yourform.submit();
}
}
if you want to get even trickier you can use prototype's nifty event handling to even set actions based on the id of your choice. for example, tossing the following in if you're using prototype would get you the id of the element the enter key was hit in:
Code:
var id = Event.element(evt);
then you could decide whether or not you want an action to occur based on the id. just a thought. i use something like this on a big webform with ajax updater to submit everything and update on the fly.
and actually, that's what the "evt.which : window.event.keyCode" line does... it figures out which browser you're using since they do handle them differently.
and actually, that's what the "evt.which : window.event.keyCode" line does... it figures out which browser you're using since they do handle them differently.
are you getting an error in ie?
Ive tested it on 2 different machines, and on both it doesn't work in IE7. Basically it just goes down to the next line as if the javascript wasn't in place.
throw a return false in there if you like. should kill the literal keypress. then figure out why it doesn't like your submit... which is probably where the problem is. i've got that code in a live web app being used by bunches of people using both ie and ff, with no complaints... it does work.