Archive

Archive for July, 2011

JQuery to Validate DropdownList

Hi try this Example to JQuery to Validate DropdownList

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default20.aspx.cs" Inherits="Default20" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("input[type=submit][id*=btn]").click(function() {
                if (parseInt($("select[id*=ddl]").attr("selectedIndex")) <= 0) {
                    alert("Select some value");
                    return false;
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:DropDownList ID="ddl" runat="server">
     <asp:ListItem>please select</asp:ListItem>
     <asp:ListItem>1</asp:ListItem>
     <asp:ListItem>2</asp:ListItem>
     <asp:ListItem>3</asp:ListItem>
     <asp:ListItem>4</asp:ListItem>
     <asp:ListItem>5</asp:ListItem>
     </asp:DropDownList>
    <asp:Button ID="btn" runat="server" Text="Submit" />
    </div>
    </form>
</body>
</html>

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Jquery