Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Date Range Selection in datepicker

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 328
    Comment on it

    Many times we need to select from date which should not be the greater than current date and to date must not be less than from particular date. In this blog illustrate how we can select the date range in datapicker.
    We can achieve this with the following code

    Firstly,
         CSS files add in header Section

     

    <link href="~/Content/themes/base/datepicker.css" rel="stylesheet" />
    
     <link href="~/Content/themes/base/core.css" rel="stylesheet" />
    
     <link href="~/Content/themes/base/theme.css" rel="stylesheet" />
    

     

    Then, Add the Html page

    <div class="form-horizontal">
        <div class="form-group">
    
            <label class="control-label col-md-2">From Date</label>
            <div class="col-md-2">
                <input type="text" id="FromDate" class="form-control" placeholder="From Date" />
            </div>
    
            <label class="control-label col-md-2">To Date</label>
            <div class="col-md-2">
                <input type="text" id="ToDate" class="form-control" placeholder="To Date" />
            </div>
        </div>
    </div>

     

     

    Then,
    Add the script for calendar.

    JavaScript files need to be added at the bottom of the layout page

    @section scripts{
    <script>
        $('#FromDate').datepicker({
            maxDate: "0D",
            onClose: function (selectedDate) {
                $("#ToDate").datepicker("option", "minDate", selectedDate);
            }
        });
    
        $('#ToDate').datepicker({
            maxDate: "0D",
            onClose: function (selectedDate) {
                $("#FromDate").datepicker("option", "maxDate", selectedDate);
            }
        });
    </script>
    }
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: