禁用基于下拉列表选择 asp.net JavaScript 启用文本框

disable enable textbox based on dropdown selection asp.net javascript

本文关键字:JavaScript net 启用 文本 asp 选择 下拉列表      更新时间:2023-09-26

大家周五快乐!我正在尝试根据下拉选择启用/禁用文本框。如果下拉列表选择了索引 == 0,则应启用文本框,否则应禁用它。这是我尝试过的:

 <tr>
                            <td></td>
                            <td class="selection">
                            <asp:dropdownlist id="ddlWindSpeed" onchange="HideTextBox(this);" runat="server" />
                            </td>
                            <td class="formField">
                                <asp:textbox id="txtActualWindSpeed" MaxLength="50" runat="server" />
                            </td>

这是JS函数:

function HideTextBox(ddlId)
            {
             var ControlName = document.getElementById(ddlId.id);
             if(ControlName.value == 0)  //it depends on which value Selection do u want to hide or show your textbox
             {
                 document.getElementById('txtActualWindSpeed').style.display = '';
             }
             else
             {
                 document.getElementById('txtActualWindSpeed').style.display = 'none';
             }
        } 
                        </tr>

使用它我收到此消息:

SCRIPT5007:无法获取属性"style"的值:对象为 null 或未定义

知道我做错了什么吗?谢谢,拉齐亚尔

尝试document.getElementById('<%=txtActualWindSpeed.ClientID%>')