用于从其他下拉菜单中选择选项时选择下拉列表选项的javascript [英] javascript for selecting option of dropdownlist on selecting option from other dropdown
本文介绍了用于从其他下拉菜单中选择选项时选择下拉列表选项的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我选择下拉列表选项时我需要javascript然后应该自动选择第二个下拉选项
解决方案
根据您的需要扩展此功能: -
函数ChngDDl2()
{
var ddlValue = document.getElementById( <%= ddl1.ClientID%>)。值跨度>;
if (ddlValue == 1 )
{
document。 getElementById( <%= ddl2.ClientID%>)。 value = 1;
}
}
你没有为下拉列表项分配值
这是你的最终解决方案: -
函数ChngDDl2(){
var ddlValue = document.getElementById(<% = ddl1.ClientID %> )。value;
if(ddlValue ==1){
document.getElementById(<% = ddl2.ClientID %> )。value =这是aple;
}
if(ddlValue ==2){
document.getElementById(<% = ddl2.ClientID < span class =code-pagedirective>%> )。value =这是洋葱;
}
}
< asp:DropDownList ID = ddl1 onchange < span class =code-keyword> = ChngDDl2(); runat = server >
< asp:ListItem value = 1 text = 一个 > < / asp:ListItem >
< asp:ListItem 值 = 2 text = two > < / asp:ListItem >
< / asp:DropDownList >
< asp:DropDownList ID = ddl2 runat = server >
< asp:ListItem value = 1 text = > < / asp:ListItem >
& lt; asp:ListItem value = 2 text = > < / asp:ListItem >
< / asp:DropDownList > 跨度>
i need javascript when i select option of dropdownlist then option of 2nd dropdown should be automatically selected
解决方案
Expand this function with your needs:-
function ChngDDl2() { var ddlValue=document.getElementById("<%=ddl1.ClientID%>").value; if(ddlValue == 1) { document.getElementById("<%=ddl2.ClientID%>").value="1"; } }
you have not assigned values to dropdown listitems
This is your final soln:-
function ChngDDl2() { var ddlValue = document.getElementById("<%=ddl1.ClientID%>").value; if (ddlValue == "1") { document.getElementById("<%=ddl2.ClientID%>").value = "This is aple"; } if (ddlValue == "2") { document.getElementById("<%=ddl2.ClientID%>").value = "This is onion"; } } <asp:DropDownList ID="ddl1" onchange="ChngDDl2();" runat="server"> <asp:ListItem value="1" text="one"></asp:ListItem> <asp:ListItem value="2" text="two"></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddl2" runat="server"> <asp:ListItem value="1" text=""></asp:ListItem> <asp:ListItem value="2" text=""></asp:ListItem> </asp:DropDownList>
这篇关于用于从其他下拉菜单中选择选项时选择下拉列表选项的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文