简体   繁体   English

Javascript / HTML错误“属性“ selectReason”的值是null或未定义,不是函数对象

[英]Javascript/HTML error “the value of the property “selectReason” is null or undefined, not a function object

Hi I am new to javascript and html and was wondering if someone could help me understand why this error keeps occuring. 嗨,我是javascript和html的新手,想知道是否有人可以帮助我理解为什么此错误不断发生。 The basic idea is that i have a dropdownlist that is populated with several options. 基本思想是我有一个下拉列表,其中填充了多个选项。 When the customer selects an option an onchange event fires that will write the value of the selected option into a textarea. 当客户选择一个选项时,将触发一个onchange事件,该事件会将所选选项的值写入文本区域。 However when i debug it I get the message above I have included the relevant snippets of code below: 但是,当我调试它时,我得到上面的消息,我在下面包含了相关的代码片段:

function selectReason() {
    var selectindex = document.getElementById("selectmessage").selectedIndex;    
    var selecttext = document.getElementById("selectmessage").value;
    document.getElementById("Txt").value = selecttxt;
}

<TR style="DISPLAY: none; VISIBILITY: hidden" id=sel>
    <TD width="60%" align=left>Please select a reason</TD>
    <TD width="40%" align=left>
        <SELECT id="selectmessage" onchange="selectReason()" style="WIDTH: 425px"></SELECT>
    </TD>
</TR>

You might be missing your <table> tags as that was causing a problem for me. 您可能缺少<table>标记,因为这对我造成了问题。 Your provided snippet also has var selecttext and document.getElementById("Txt").value = selecttxt; 您提供的代码段还包含var selecttextdocument.getElementById("Txt").value = selecttxt; <- missing an e. <-缺少e。

The provided snippet below works for me. 以下提供的代码段对我有用。 Possibly just failing to close a tag somewhere in your function/html. 可能只是无法在您的function / html中的某个位置关闭标签。

Also (this could be you added inline to provide a better picture) you should avoid inline styles and (to me) functions. 另外(这可能是您添加内联以提供更好的图片),您应该避免使用内联样式和(对我而言)函数。 Include a .css and .js file. 包括一个.css和.js文件。

 function selectReason() { var selectindex = document.getElementById("selectmessage").selectedIndex; var selecttext = document.getElementById("selectmessage").value; var elem = document.getElementById("hey"); elem.innerHTML = selecttext; } // Events to attach function init () { var elem = document.getElementById('selectmessage'); elem.addEventListener('change', selectReason) } // Run 'init' when the DOM is ready (jQuery's $(document).ready() ) document.addEventListener("DOMContentLoaded", init, false); 
 <table> <TR> <TD>Please select a reason</TD> <TD> <SELECT id="selectmessage"> <option>Hello</option> <option>Yes</option> </SELECT> </TD> </TR> <tr> <td id='hey'></td> </tr> </table> 

Maybe this could help you 也许这可以帮助您

<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>

<body>

    <table>
        <tbody>
            <tr>
                <td>
                    <select name="" id="selectmessage">
                        <option value="red">red</option>
                        <option value="gree">green</option>
                        <option value="blue">blue</option>
                    </select>
                </td>
            </tr>
        </tbody>
    </table>

    <textarea name="" id="txt" cols="30" rows="10">


    </textarea>

    <script type="text/javascript">
        $(document).on('ready', function(){
            $('#selectmessage').on('change', function(){
                var val = $(this).val();

                var txt = $('#txt');

                    txt.val(val);
            });
        });
    </script>

</body>
</html>

hope :) 希望:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript:属性的值为null或未定义,不是Function对象 - Javascript: The value of the property is null or undefined, not a Function object 无法获取属性“ length”的值:对象为null或未定义-Javascript错误 - Unable to get value of the property 'length': object is null or undefined - Javascript Error 0x800a138f - JavaScript运行时错误:属性&#39;$&#39;的值为null或未定义,而不是Function对象 - 0x800a138f - JavaScript runtime error: The value of the property '$' is null or undefined, not a Function object 0x800a138f-JavaScript运行时错误:属性&#39;&#39;的值是null或未定义,不是Function对象 - 0x800a138f - JavaScript runtime error: The value of the property ''is null or undefined, not a Function object IE 抛出 JavaScript 错误:属性 &#39;googleMapsQuery&#39; 的值为 null 或未定义,不是函数对象(适用于其他浏览器) - IE throws JavaScript Error: The value of the property 'googleMapsQuery' is null or undefined, not a Function object (works in other browsers) 在ie8 jQuery错误中(属性“ $”的值为null或未定义,不是Function对象) - In ie8 jquery error(The value of the property '$' is null or undefined, not a Function object) 错误:属性“ warn_redirect”的值为null或未定义,不是Function对象 - Error: The value of the property 'warn_redirect' is null or undefined, not a Function object 属性“ gatherItemInfo”的值为null或未定义,不是Function对象 - The value of the property 'gatherItemInfo' is null or undefined, not a Function object 属性&#39;addEvent&#39;的值为null或未定义,不是Function对象 - The value of the property 'addEvent' is null or undefined, not a Function object “ openNewWin”属性的值为null或未定义,不是Function对象 - The value of the property 'openNewWin' is null or undefined, not a Function object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM