locked
Need to set a dropdown as Mandatory field RRS feed

  • Question

  • User6861111 posted

    Hi Sir,

    I have been asked to code as - When user clicks and DOWNLOAD Button, it has to check whether user has selected any option from two different dropdown  buttons. 

    If they have selected the Options and click the DOWNLOAD Button then it allows to download the data. But when user clicks download without any selection in dropdown then a Message should popup " Choose the values from Calendar Year and Account".  (Note: In default the OPTION "ALL" will be selected but when user clicks Download button it should asks to select any other options from Calendar Year and Account) 

    Just need to set this criteria in the below code. 

      $('#btnDownloadSU').bind('click', function () {
                $.messager.confirm('Go to download spreadsheet data file?', 'Are you going  to download spreadsheet data file ?',
                function (isOk) {
                    if (isOk) {
                        var date = new Date();
                        var fileName = userID + '_' + date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear() + "-" + date.getHours() + date.getMinutes() + date.getSeconds();
                        //open the download window to download file
                        window.open('../DataServices/ActualCostsVSPOR.ashx?action=SUAccountVariance&'
                            + '&FileName=' + fileName
                            + '&Account=' + Accounts.GetCheckedItems().IDs
                            + '&CalYear=' + CalYear.GetCheckedItems().IDs);
    
                    }
                });
            });

    Please help, i am strugling in this for past 2 weeks.

    Wednesday, March 23, 2016 7:50 AM

Answers

  • User-986267747 posted

    Hi 9791736978,

    If they have selected the Options and click the DOWNLOAD Button then it allows to download the data. But when user clicks download without any selection in dropdown then a Message should popup " Choose the values from Calendar Year and Account".  (Note: In default the OPTION "ALL" will be selected but when user clicks Download button it should asks to select any other options from Calendar Year and Account) 

    According to your description, you'd like to ensure that the user have select the options but the option called all for these dropdownlist. You could refer to the following code to check if the use have selected other option using jquery.

       <asp:Button ID="Button1" runat="server" Text="Button"  />
            <asp:DropDownList ID="CalendarYearDll" runat="server" >
                <asp:ListItem Selected="True" Value="" >All</asp:ListItem>
                <asp:ListItem  Value="2012">2012</asp:ListItem>
                <asp:ListItem  Value="2013">2013</asp:ListItem>
                <asp:ListItem  Value="2014">2014</asp:ListItem>
                <asp:ListItem  Value="2015">2015</asp:ListItem>
                <asp:ListItem  Value="2016">2016</asp:ListItem>
                <asp:ListItem  Value="2017">2017</asp:ListItem>
            </asp:DropDownList>
    
            <asp:DropDownList ID="AccountDll" runat="server" >
                <asp:ListItem Selected="True" Value="" >All</asp:ListItem>
                <asp:ListItem  Value="1">1</asp:ListItem>
                <asp:ListItem  Value="2">2</asp:ListItem>
                <asp:ListItem  Value="3">3</asp:ListItem>
                <asp:ListItem  Value="4">4</asp:ListItem>
                <asp:ListItem  Value="5">5</asp:ListItem>
                <asp:ListItem  Value="6">6</asp:ListItem>
            </asp:DropDownList>
           $("#Button1").click(function () {
    
                    var CalendarYearDll = $('#CalendarYearDll').val();
    
                    var AccountDll = $('#AccountDll').val();
    
                    if (!(CalendarYearDll && AccountDll))
                    {
                        alert("Choose the values from Calendar Year and Account");
                        return false;
                    }
                   
    
                });

    I hope it's helpful to you.

    Best Regards,

    Klein zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 24, 2016 3:15 AM