如何验证下拉列表 [英] How to validate dropdown list

查看:93
本文介绍了如何验证下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下拉列表和子下拉列表如果我在主下拉列表中选择水果选项子选项将显示多选验证在保存选项中选择的任何一个。

告诉我任何想法谢谢。



我的尝试:



< asp: DropDownList ID =DropDownList4class =form-controlrunat =server>

< asp:ListItem Value =1> - SELECT -

< asp:ListItem Value =2>水果

< asp:ListItem Value =3> veg









< asp:ListBox ID =Select49SelectionMode =Multiplerunat =server>

< asp:ListItem Value =1> 4

< asp:ListItem Value =2> 8

< asp:ListItem Value =3> 12

< asp:ListItem Value =4> 16

解决方案

用于验证



< pre lang =HTML> < asp:button id = btnSave text = 保存 onclientclick = 返回ValidateFun(); runat = server onclick = btnSave_Click xmlns:asp = #unknown / >





Javascript:



< script> 
var ValidateFun = function()
{
var listbox = document.getElementById('<%= Select49.ClientID%>');
var count = listbox.selectedOptions.length;
if(count == 0)
{alert('Please select !!');返回false; }
返回true;
}
< / script>


i have dropdown list and also sub drop down list if i select fruit select in main dropdown list sub option will display that is multi select validate any one selected in save option.
tell me any idea thanks regards

What I have tried:

<asp:DropDownList ID="DropDownList4" class="form-control" runat="server">
<asp:ListItem Value="1">--SELECT--
<asp:ListItem Value="2">fruit
<asp:ListItem Value="3">veg




<asp:ListBox ID="Select49" SelectionMode="Multiple" runat="server">
<asp:ListItem Value="1"> 4
<asp:ListItem Value="2">8
<asp:ListItem Value="3">12
<asp:ListItem Value="4">16

解决方案

For validation

<asp:button id="btnSave" text="Save" onclientclick="return ValidateFun();" runat="server" onclick="btnSave_Click" xmlns:asp="#unknown" />



Javascript:

<script>
    var ValidateFun = function ()
    {
        var listbox = document.getElementById('<%= Select49.ClientID%>');
        var count = listbox.selectedOptions.length;
        if (count == 0)
        { alert('Please select !!'); return false; }
        return true;
    }
</script>


这篇关于如何验证下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆