onBlur 函数未执行

发布于 2024-10-15 11:31:52 字数 1414 浏览 6 评论 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 数组中)并用名称替换它。警报在那里用于调试目的,但当我运行该页面时,我没有收到任何警报。有什么想法吗?

I've been searching for an answer for why this isn't working for several hours, and I'm stumped.

Here's the script including the javascript and form involved.

<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>

The two PHP echo statements are the parameters for the Arrays. The complete(this.value) function is supposed to take a 3 letter code (in the iList array) and substitute it with a name. The alerts are in there for debugging purposes, but i don't get either alert when i run the page. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2024-10-22 11:31:52

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];
            }
        }
    }

this.frmMain
is not defined anywhere

change

onblur = "complete(this.value)"

to

onblur = "complete(this)"

and use

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];
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文