在firefox JSP中验证文本字段onkeypress事件

validate textfield onkeypress event in firefox JSP

本文关键字:字段 onkeypress 事件 文本 验证 firefox JSP      更新时间:2023-09-26

我已经编写了onKeyPress事件,当用户输入一些文本时验证文本,然后从某些字段中跳出选项卡应该验证文本,如果没有输入任何内容或输入不正确的值,应该给出错误通知用户,焦点应该回到字段,用户不得被允许进入下一个字段,而不是字段的帮助按钮。

<jade:input type="text" name="dtxtDesigCd" 
    value="" size="10" maxlength="8" 
    classname="input" disabledclass="disabled-input" style="color: black"  
    datasource="dsDesigHourDetail:desigCode"
    onkeypress= "checkDesignation(this, event);">
</jade:input> 

我还有一个自定义JSP标记"PickList",它基本上是一个显示的按钮从帮助窗口中选择相关字段和从数据库中选择的记录后,一个带有数据库帮助的模态窗口显示在JSP的文本字段中。

修改后的SOFIA框架被我们以前的供应商使用,现在我必须维护代码。早期代码的问题是这个按钮必须双击才能获得帮助,因为它使用onblur而不是onkeypress,并且需要多次尝试,因为它一直给出错误。

之前使用onblur的代码是

    onblur="setValue('DESIGNATION');" onkeyup="capitalize(this);"

现在已被

所取代
    onkeypress= "checkDesignation(this, event);">
JSP中帮助按钮/PickList的代码如下:
<rap:pickfromlist name="picklistDesignation" datasource="dsDesigHourDetail" 
    pflheading="Designation Details" focusfield="dtxtDesigCd"
    pflcolumnsdesc="Designation Code, Description" 
    fieldlist="distinct emp_desig_cd, emp_desig_desc " 
    lookuptable="pmm_designation" orderby="emp_desig_cd"
    targetproperty="desigCode, designation" 
    whereclause=" executive_post='N' and crew_flg = 'N'" /> 

在此字段中,指定的描述是在从picklist中选取或通过setValue方法提交表单后捕获的,该方法通过表单中的隐藏变量动作将值传递给服务器并提交表单。

<jade:input type="text" name="dlblDesigDesc" value="" size="50" 
    classname="labeltext" style="color: black" 
    datasource="dsDesigHourDetail:designation" enabled="False">
</jade:input>

checkDesignation(obj, evt)定义为

function checkDesignation(obj, evt) {
    var evt = (evt) ? evt : (window.event) ? event : null;
    if (evt) {
        var len = TrimString(obj.value).length;
        alert("Designation : " + obj.value);
        if (evt.keyCode == 9 && len >= 0) {
            if (len == 0) {
                setErrMessage('Designation must be entered and not blank');
                document.forms[0].htmlPageTopContainer_pageForm_detailDesigHourForm_dtxtDesigCd.focus();
                document.forms[0].htmlPageTopContainer_pageForm_detailDesigHourForm_dtxtDesigCd.value = '';
                setValue('DESIGNATION');
                return false;
            } else {
                capitalize(obj);
                setValue('DESIGNATION');
                return true;
            }
        }
    }
} 

check this

    $("#textbox").bind("onKeyPress ", function (e) {
                if (e.altKey || e.ctrlKey || e.shiftKey){
                    return true;
    }
    else{
    // you have this text box inner text in this.val() and can be checked with 
           your validate function.
    }
            });