What event do I need to supress to stop IE from "Dinging" when I press enter in a text box?
Asked Answered
K

5

8

On simple forms with one text box pressing enter submits the form (and this is great for easy search forms)

However on a form with multiple fields, pressing Enter in an input="text" box won't do anything (e.g. submit) but in IE it "Dings" as if you have tried to delete an undeletable object.

The question is... what event do I need to suppress in IE to stop this sound? e.g. if I have a username/password form, I DO want the enter key to submit the form, but I certainly don't want the "error" sound.

Example site with the sound: http://www.sears.com/shc/s/StoreLocatorView?storeId=10153&catalogId=12605 Just press Enter in any of the text fields. Ding!, Ding!, Ding!

Non-IE users, the sound is the: Program Events > Windows > Default Beep ("Windows XP Ding.wav")

Kenneth answered 4/6, 2009 at 19:10 Comment(0)
K
10

Well it appears that this works:

<!-- suppress sound (and suppress submit) -->
<input type="text" onkeypress="if(window.event.keyCode == 13){return false;}"/>

<!-- suppress sound (BUT allow submit) -->
<input type="text" onkeypress="if(window.event.keyCode == 13){this.form.submit();return false;}"/>
Kenneth answered 4/6, 2009 at 19:36 Comment(3)
Won't this prevent the form from being submitted?Nonintervention
yes it will (on a single field form) but the key is the return false. I can do that after I do other stuff, including submitting the form. ;-)Kenneth
Jesus, why is this even a thing in IE STILL? But thank you! It worked.Hurt
D
2
$("#logonForm").keypress(function (e) {
            if (e.keyCode == '13') {
                if (instance.Validate(instance)) {
                    document.forms["logonForm"].submit();
                    return false;  //Do not delete, suppresses ding in IE... :P
                }
            }
        });

This works, we use it.

Dochandorrach answered 17/6, 2011 at 7:42 Comment(0)
A
0

He is right. The text field you want, not to annoy you with ding song

only add

onkeypress="if(window.event.keyCode == 13){return false;}"

to you input tag

<input type="whatever"  onkeypress="if(window.event.keyCode == 13){return false;}" >

But don't do this in submit or button input ok. Only to the text fields, so you don't get annoyed by ding! ding! now. I checked.

Agar answered 20/2, 2010 at 7:41 Comment(0)
I
0
$("#txtSomething").keypress(function (e) {
        if (e.which == 13) {

            e.Handled = true; //This will prevent the "ding" sound

            //Write the rest of your code
        }
    });
Idiosyncrasy answered 13/11, 2013 at 1:0 Comment(0)
D
-1

I guess that is controlled by OS & hence, it cant be controlled using javascript.

Deposit answered 4/6, 2009 at 19:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.