Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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")

like image 961
scunliffe Avatar asked Jun 04 '09 19:06

scunliffe


2 Answers

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;}"/>
like image 189
scunliffe Avatar answered Nov 16 '22 21:11

scunliffe


$("#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.

like image 38
anon Avatar answered Nov 16 '22 21:11

anon