繁体   English   中英

禁用基于下拉选择asp.net javascript的启用文本框

[英]disable enable textbox based on dropdown selection asp.net javascript

大家星期五快乐! 我试图基于下拉选择启用/禁用文本框。 如果下拉列表选择的索引== 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:无法获取属性“样式”的值:对象为null或未定义

知道我在做什么错吗? 谢谢,Laziale

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM