在下拉列表中选择其他人时,启用/禁用文本框的Javascript [英] Javascript for enabled/disabled textbox when select others in dropdownlist
问题描述
< asp:TextBox ID =txtidrunat =server>
< asp:DropDownList ID =ddlidrunat =serveronClick =javascript:showReadonly(''<%= txtid.ClientID%>'',this.value);>
< asp :ListItem Text =Select/>
< asp:ListItem Text =English/>
< asp:ListItem Text =Other Course />
我有一个文本框和一个下拉列表,dropdownlist有listitems select,英文当我在下拉列表中选择其他课程时,我想启用文本框,其他情况下我想要禁用文本框。
我写了下面的代码,它不能正常工作。
plz为我提供任何建议。
注意:这里document.getElementbyID不识别文本框ID所以它会显示错误消息,如文档.getElementbyID(..)为null或不是对象
如何解决这个问题PLZ帮助我。
< script type =text / javascript>
函数showReadonly(txtobj,valobj)
{
if(valobj ==其他课程)
{
document.getElementById(txtobj).disabled = false;
document.getElementById(txtobj).focus() ;
}
else {
document.getElementById(txtobj).disabled = true;
}
< / script>
谢谢&egards
venkat
<asp:TextBox ID="txtid" runat="server">
<asp:DropDownList ID="ddlid" runat="server" onClick="javascript:showReadonly(''<%=txtid.ClientID%>'',this.value);">
<asp:ListItem Text="Select" />
<asp:ListItem Text="English" />
<asp:ListItem Text="Other Course" />
I have one textbox and one dropdown list ,dropdownlist have listitems select,English and other course.
when i select other course in the dropdownlist i want to enable textbox,other cases i want disabled textbox.
I written following code it is not working.
plz give any suggetions for me.
Note:Here document.getElementbyID is not identify textbox ID so It will show error message like document.getElementbyID(..) is null or not an object
How can solve this problem plz help me.
<script type="text/javascript">
function showReadonly(txtobj, valobj)
{
if (valobj == "Other Course")
{
document.getElementById(txtobj).disabled = false;
document.getElementById(txtobj).focus();
}
else {
document.getElementById(txtobj).disabled= true;
}
</script>
Thanks&egards
venkat
推荐答案
在运行时检查你的文本框id'并用那个替换它...
实际上javascript无法找到该文本框。
Check your textbox id''s at runtime and replace it with that one...
Actually javascript not able to find that textbox.
您好,
1.检查javascript函数是否为能否找到文本框
2.查看IE正在报告的任何错误
3.设置断点d调试javascript。
我跳你会发现究竟是什么错误
据我所知无法通过javascript找到文本框控件这就是为什么它无法禁用它。
希望这有帮助
Hi,
1. Check whether the javascript function is able to find the textbox or not
2. See any error that IE is reporting
3. Put a breakpoint and debug the javascript.
I hopw you will find what exactly the error
As I know it not able to find the textbox control through javascript thats why it is unable to disable it.
Hope this helps
请检查这个博客
javascript-for-enableddisabled
这篇关于在下拉列表中选择其他人时,启用/禁用文本框的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!