onBlur函数没有执行

时间:2011-02-03 21:13:51

标签: javascript onblur

我一直在寻找一个答案,为什么这个工作几个小时都没有用,我很难过。

这是包含所涉及的javascript和表单的脚本。

<script language="Javascript" type="text/javascript">
    function complete(init){
        alert ("in function with " + init);
        var aList = new Array(<?php echo $aList; ?>);
        var iList = new Array(<?php echo $iList; ?>);
        for (var i = 0; i < iList.length; i++){
            if (init == iList[i]){
                alert ("replacing " + init + " with " + aList[i]);
                this.frmMain.txtAtty.value = aList[i];
            }
        }
    }
</script>

<FORM METHOD="POST" NAME="frmMain" ACTION=<?php echo $_SERVER["PHP_SELF"]; ?>>
    <table width="75%" align="center">
        <tr>
            <td width="25%" align="right">Name:</td>
            <td>
                <input type="text" name="txtSender" size="30" value=""/><span class="noteText"> Your Name</span>
            </td>
        </tr>
        <tr>
            <td width="25%" align="right">Attorney:</td>
            <td>
                <input type="text" name="txtAtty" size="30" value="" onblur = "complete(this.value)">
            </td>
        </tr>

两个PHP echo语句是Arrays的参数。完整的(this.value)函数应该采用3字母代码(在iList数组中)并用名称替换它。警报在那里用于调试目的,但是当我运行页面时我没有得到任何警报。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

this.frmMain 没有在任何地方定义

变化

onblur = "complete(this.value)"

onblur = "complete(this)"

并使用

function complete(field){
  var init = field.value;
        alert ("in function with " + init);
        var aList = new Array(<?php echo $aList; ?>);
        var iList = new Array(<?php echo $iList; ?>);
        for (var i = 0; i < iList.length; i++){
            if (init == iList[i]){
                alert ("replacing " + init + " with " + aList[i]);
                field.value = aList[i];
            }
        }
    }