You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Erik Weber <er...@mindspring.com> on 2004/09/01 15:52:53 UTC
[OT] "Enter" key listener for form submittal
I found this JavaScript, which is supposed to listen for the "Enter" key
on any browser (and submit the form on keypress). However, it doesn't
seem to be working in IE:
<script language="JavaScript">
if (document.layers) document.captureEvents(Event.KEYDOWN);
document.onkeydown =
function (evt) {
var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : evt.keyCode;
if (keyCode == 13) {
document.forms[0].submit();
}
}
</script>
Does anyone have an "Enter" key listener that has been shown to work in
all browsers, or know what is wrong with this one?
Thanks,
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] "Enter" key listener for form submittal
Posted by Erik Weber <er...@mindspring.com>.
And, now I will repost the code which was omitted in a reply:
Erik Weber wrote:
> I found this JavaScript, which is supposed to listen for the "Enter"
> key on any browser (and submit the form on keypress). However, it
> doesn't seem to be working in IE:
>
> <script language="JavaScript">
> if (document.layers) document.captureEvents(Event.KEYDOWN);
> document.onkeydown = function (evt) {
> var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : evt.keyCode;
> if (keyCode == 13) {
> document.forms[0].submit();
> }
> }
> </script>
>
>
> Does anyone have an "Enter" key listener that has been shown to work
> in all browsers, or know what is wrong with this one?
>
> Thanks,
> Erik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] "Enter" key listener for form submittal
Posted by David Durham <da...@scott.af.mil>.
Erik Weber wrote:
>> Also, does document.forms[0].submit() trigger the submit with a submit
>> value of cancel? Does that make since?
>
>
> Hmm, would it not fail also on Mozilla if that were true?
Perhaps. I just glanced at the thread, so I have a cursory
understanding of the problem.
- Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] "Enter" key listener for form submittal
Posted by Erik Weber <er...@mindspring.com>.
David Durham wrote:
> Erik Weber wrote:
>
>> I found this JavaScript, which is supposed to listen for the "Enter" key
>> on any browser (and submit the form on keypress). However, it doesn't
>> seem to be working in IE:
>>
>> <script language="JavaScript">
>> if (document.layers) document.captureEvents(Event.KEYDOWN);
>> document.onkeydown =
>> function (evt) {
>> var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : evt.keyCode;
>> if (keyCode == 13) {
>> document.forms[0].submit();
>> }
>> }
>> </script>
>>
>>
>> Does anyone have an "Enter" key listener that has been shown to work in
>> all browsers, or know what is wrong with this one?
>
>
> Consider returning false in order to halt the normal event
> propagation. It may be that you are triggering the right form, but
> the "enter" event is being passed on and submitting the cancel button.
Thanks, I will try that.
>
> Also, does document.forms[0].submit() trigger the submit with a submit
> value of cancel? Does that make since?
Hmm, would it not fail also on Mozilla if that were true?
Thanks,
Erik
>
>
> - Dave
>
>
>
>
>
>> Thanks,
>> Erik
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] "Enter" key listener for form submittal
Posted by David Durham <da...@scott.af.mil>.
Erik Weber wrote:
> I found this JavaScript, which is supposed to listen for the "Enter" key
> on any browser (and submit the form on keypress). However, it doesn't
> seem to be working in IE:
>
> <script language="JavaScript">
> if (document.layers) document.captureEvents(Event.KEYDOWN);
> document.onkeydown =
> function (evt) {
> var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : evt.keyCode;
> if (keyCode == 13) {
> document.forms[0].submit();
> }
> }
> </script>
>
>
> Does anyone have an "Enter" key listener that has been shown to work in
> all browsers, or know what is wrong with this one?
Consider returning false in order to halt the normal event propagation.
It may be that you are triggering the right form, but the "enter" event
is being passed on and submitting the cancel button.
Also, does document.forms[0].submit() trigger the submit with a submit
value of cancel? Does that make since?
- Dave
>Thanks,
>Erik
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org