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

孤街浪徒 提交于 2019-12-04 03:17:16

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

Ammar

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.

$("#txtSomething").keypress(function (e) {
        if (e.which == 13) {

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

            //Write the rest of your code
        }
    });

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!