Validate value of Dropdownlist (jquery)

2 posts, 0 answers
  1. Kurt Kluth
    Kurt Kluth avatar
    144 posts
    Member since:
    Oct 2009

    Posted 30 Jan 2014 Link to this post

    Currently have 2 dropdown lists (month & year) that I would like to validate they are not blank and verify that they aren't for a future date.  I am unable to get the value via jquery.  Suggestions?

    <script type=
    "text/javascript">
        var oWnd;
        //<![CDATA[
        function daysInMonth(month, year) {
            return new Date(year, month, 0).getDate();
        }
     
        function openRadWin(InMode) {
            //Removes the scroll bars from the Parent Window
            removeScrollbars();
     
            var MonthInput = $find("<%= _NewMonth.ClientID %>");
            var YearInput = $find("<%= _newYear.ClientID %>");
            var newVal = $('#_newYear').val();
            var dropFind = $find("<%= _NewMonth.ClientID %>");
            var valueFind = dropFind.get_value();
     
            alert(valueFind);
    }
    </script>




    New statement cycle date <strong>(mm/dd/yyyy)</strong>:
    <telerik:RadDropDownList ID="_NewMonth" runat="server" DefaultMessage="Select a Month">
        <Items>
            <telerik:DropDownListItem runat="server" Selected="false" Text="January" Value="1" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="February" Value="2" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="March" Value="3" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="April" Value="4" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="May" Value="5" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="June" Value="6" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="July" Value="7" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="August" Value="8" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="September" Value="9" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="October" Value="10" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="November" Value="11" />
            <telerik:DropDownListItem runat="server" Selected="false" Text="December" Value="12" />
        </Items>
    </telerik:RadDropDownList>
    <telerik:RadDropDownList ID="_NewYear" runat="server">
    </telerik:RadDropDownList>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jan 2014 in reply to Kurt Kluth Link to this post

    Hi Kurt Kluth,

    Please try the following JavaScript which works fine at my end.

    JavaScript:
    <script type="text/javascript">
        function openRadWin(InMode) {
            var newVal = $('#_NewYear').val();
            var valueFind = $find("<%=_NewMonth.ClientID %>").get_selectedItem().get_value();
            if (newVal != "" && valueFind != "") {
                var date = new Date();
                var month = date.getMonth() + 1;
                var year = date.getFullYear();
                if (newVal > year)
                    alert("validation fails");
                if (newVal == year) {
                    if (valueFind > month)
                        alert("validation fails");
                }
                else
                    alert("validation success");
            }
        }
    </script>

    Hope this will helps you.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top