[thelist] Can't submit form data with 'enter' key in IE

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Tue Mar 7 15:27:56 CST 2006


Hi Jim,

   Actually, you're supposed to put the event handler inside an existing tag (like the body tag), not on its own :)

<body onkeydown="blahblahblah">

   If you just want it to work for the field in question, you can stick it inside the input tag:

<input type="text" onkeydown="blahblahblah()" />

   What I mean by encapsulation is to take the main functionality out of the tag and put it into a Javascript function, for a more modular approach.  For example:

<input type="text" onkeydown="checkSubmit()" />

<script language="javascript">
function checkSubmit() {
   if(!window.event) { return; }
   if(window.event.keyCode == 13) { document.forms[0].submit(); }
   }
</script>

Cheers,

Peter

 From: "Jim Davis" jim4realty at gmail.com

Peter,

Thanks for the reply. I'm not sure what you mean by "encapsulate". I
inserted:

just after but no joy.

Jim

On 3/7/06, EasyListBox.com Peter Brunone wrote:
>
> It should be doing that by default, or so I thought... if not, you can add
> the following to your body element (or any sub-element therein):
>
> onkeydown="if(window.event.keyCode==13){document.forms[0].submit();}"
>
> Of course you'd probably want to encapsulate this to avoid errors in
> Mozilla, which uses event.which instead of event.keyCode.
>
> HTH,
>
> Peter



More information about the thelist mailing list