捕获“;输入键“;适用于IE,但不适用于Cognos中使用的Firefox

Catching "Enter Key" works with IE but not Firefox - used in Cognos

本文关键字:适用于 Firefox Cognos 输入 IE 捕获 不适用      更新时间:2023-09-26

我正在使用Cognos,并试图捕获enter键,以便在提交提示之前检查用户的输入。

即使你没有cognos的经验,如果你看看我的代码,我也会很感激:)这几乎是一个用于业务报告的拖放程序。

我在我的cognos提示页面上有一个文本框提示,我正在尝试为用户输入设置最小3个字符。我已经使用HTML项目用div包围了文本框提示,如下所示。

<div onKeyDown="return keyMon(event)"> Cognos Text Box </div>

然后我有另一个HTML项,它包含函数keyMon(),如下所示:

<script>
function keyMon(e3)
{
    var key = e3 || window.event;
    if(key.keyCode == 13){
        var fW = (typeof getFormWarpRequest == "function" ?
        getFormWarpRequest() : document.forms["formWarpRequest"]);
        if ( !fW || fW == undefined) {
            fW = ( formWarpRequest_THIS_ ?
            formWarpRequest_THIS_ : formWarpRequest_NS_ );
        }
    
        var custValue = fW._textEditBoxCustomerPrompt;  
        if(custValue.value.length > 0){
            if(custValue.value.length >= 3){
                promptAction('next'); //Submit the user's input
            }else{
                alert("Please enter a search value that is 3 or more characters long.");
                return false;
            }
        }
    }
}
</script>

正如我上面所说,这对IE来说很好。当它在Firefox中运行时,它会选择Enter键,警报框会按原样弹出,但只会持续一毫秒,然后就会消失。但它仍然继续到下一页。很明显;return false"做得不多。

如有任何帮助,我们将不胜感激。

我设法在上面加了一个创可贴……我没有返回false,而是清除了参数文本框,从而使提示不提交。然后我发出警报。

如果有人能解决我最初的问题,请随时添加,因为这真的很困扰我。

<script>
function keyMon(e3)
{
    var key = e3 || window.event;
    if(key.keyCode == 13){
        var fW = (typeof getFormWarpRequest == "function" ?
        getFormWarpRequest() : document.forms["formWarpRequest"]);
        if ( !fW || fW == undefined) {
            fW = ( formWarpRequest_THIS_ ?
            formWarpRequest_THIS_ : formWarpRequest_NS_ );
        }
        var custValue = fW._textEditBoxCustomerPrompt;  
        if(custValue.value.length > 0){
            if(custValue.value.length >= 3){
                promptAction('next'); //Submit the user's input
            }else{
                //Delaying the alert box so that the user's enter press will not exit the alert box.
                setTimeout("alert('Please enter a search value that is 3 or more characters long.')",250);
                fW._textEditBoxCustomerPrompt.value = "";   
            }
        }
    }
}
</script>