Validating Dropdownlist using Javascript


Using Javascript:

<head>

<script type=”text/javascript”>
function Dropdownvalidation(source, args)
{
var DDL2 =

document.getElementById(“<%=DropDownList2.ClientID%>”);
var country =

DDL2.options[DDL2.selectedIndex].value;
if (country == “0”)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
</script>

</head>

<body>

<asp:DropDownList ID=”DropDownList2″ runat=”server” Height=”23px” Width=”131px”>
                    <asp:ListItem Value=”0″>—-Select—-</asp:ListItem>
                    <asp:ListItem Value=”10″>Cash</asp:ListItem>
                    <asp:ListItem Value=”11″>Check</asp:ListItem>
                    <asp:ListItem Value=”12″>Western Union</asp:ListItem>
                    <asp:ListItem Value=”13″>Credit Card</asp:ListItem>
                    <asp:ListItem Value=”14″>PayPal</asp:ListItem>
                    <asp:ListItem Value=”15″>Non-electronic Payment (Money Order)</asp:ListItem>
                </asp:DropDownList>
                <asp:CustomValidator ID=”CustomValidator1″ runat=”server”
                    ClientValidationFunction=”Dropdownvalidation” ControlToValidate=”DropDownList2″
                    ErrorMessage=”Please Select*”></asp:CustomValidator>

</body>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s