Toggle enter key

  • Thread starter Thread starter DavidC
  • Start date Start date
D

DavidC

I have an asp.net web page with the javascript below at the top of the page.
This works great as a user hitting the <enter> key is not "posted" and
subsitutes the tab key. However, when the user lands on the submit button
(called BtnSave) I want the <enter> key to act as normal. Does anyone know a
way to do this? Thanks.

<script type="text/javascript">
document.onkeydown = doKey;

function doKey(e) {
if (event.keyCode == 13) {
event.keyCode = 9;
return event.keyCode;
}
}
</script>
 
I have an asp.net web page with the javascript below at the top of the page.
This works great as a user hitting the <enter> key is not "posted" and
subsitutes the tab key.  However, when the user lands on the submit button
(called BtnSave) I want the <enter> key to act as normal.  Does anyone know a
way to do this?  Thanks.

    <script type="text/javascript">
        document.onkeydown = doKey;

        function doKey(e) {
            if (event.keyCode == 13) {
                event.keyCode = 9;
                return event.keyCode;
            }
        }
    </script>

What happens if you add an event handler directly to the button?

onkeypress="..." onClick="..."
 
Javascript is not my strong suit, but I added onkeypress="togglenter();" to
my button and the js function below and it did not work. When I pressed
<enter> when on the button it just issued a TAB to the next control. Can you
spot what I am doing wrong? Thanks.

function togglenter() {
if (event.keyCode == 13) {
event.keyCode = 13;
return event.keyCode;
}
}
 
Back
Top