Toggle enter key

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>
 
G

Guest

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="..."
 
D

DavidC

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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top