struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Weber <erikwe...@mindspring.com>
Subject Re: [OT] "Enter" key listener for form submittal
Date Thu, 02 Sep 2004 23:00:29 GMT
Michael, this is the original question I posted (yesterday morning):

<snip>

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?
 
</snip>

Someone noted that I really should return false after the line that 
submits the form; I have not tried it with that change.

I'm not sure about IE 6, but it didn't work in IE 5. Same story with a 
"hidden" submit button which was arranged to be the first button in the 
form:

<html:submit style="display:none"/>

Erik



Michael McGrady wrote:

> Erik Weber wrote:
>
>> Rick, I tried putting a hidden submit button (<html:submit 
>> style="display:none"/>) in front of my cancel button to intercept the 
>> "Enter" key, but again, this worked in Mozilla but not IE (just like 
>> my key listener JavaScript).
>>
>> So I'm still looking for an Enter key listener that is portable. I 
>> haven't tried every suggestion I got though.
>>
>> Erik
>>
>>
>> Rick Reumann wrote:
>>
>>> Erik Weber wrote:
>>>
>>>> Would this button then need an onclick to submit the form, or is 
>>>> that not necessary? 
>>>
>>>
>>>
>>>
>>> I haven't had to use the approach but I don't think it would be 
>>> necessary to add an onclick. Just make it's a regular submit button 
>>> and make sure it's hidden after the <html:form > tag 
>>
>>
>
> Where is the rest of this discussion?  Is it under a different 
> subject?  I am interested in the topic and probably have an answer, 
> but need to see the question to be sure.
>
> Michael
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message