0

我一直在寻找为什么这几个小时都不起作用的答案,我很困惑。

这是脚本,包括涉及的 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 语句是数组的参数。complete(this.value) 函数应该采用 3 个字母的代码(在 iList 数组中)并将其替换为名称。警报在那里用于调试目的,但是当我运行页面时我没有收到任何警报。有任何想法吗?

4

1 回答 1

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];
            }
        }
    }
于 2011-02-03T21:20:28.307 回答