Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<script type="text/javascript">
        $(function () {
            $("#deadline").datepicker();
            minDate: 0 ;
        });
    </script>

this my jquery code for datepicker(); pick date from user run time

i want to user not select previous date to today date ? . ....

thanks
Posted
Updated 7-Aug-13 19:48pm
v3
Comments
Ankur\m/ 8-Aug-13 2:17am    
What don't you check the date picker api documentation that you are using. There must be a configuration to not allow previous date.

Use below mentioned code which will restrict previous dates as desired.

JavaScript
$("#deadline").datepicker({ minDate: 0 });
 
Share this answer
 
Comments
santsho kumar 9-Aug-13 5:37am    
thank you sir
There are little changes done in your code.which are styled as Italian

C#
<script type="text/javascript">
        $(function () {
           var date = new Date();
           var currentMonth = date.getMonth();
           var currentDate = date.getDate();
           var currentYear = date.getFullYear();
           
 $("#deadline").datepicker();
           minDate: new Date(currentYear, currentMonth, currentDate),
        });
    </script>


Thanks
 
Share this answer
 
v2
Comments
Sudhakar Shinde 8-Aug-13 2:33am    
What is Italian style?? BTW how this code will restrict the previous dates?
kishore sharma 8-Aug-13 3:26am    
nothing i have styled(font style,italian,bold) the new code as italian
This part of code
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
santsho kumar 9-Aug-13 5:37am    
thanks you sir
I hope you used jquery datepicker try this:-

C#
function DatePicker()
            {
               var startDateTextBox = $('#<%= txtFromDate.ClientID%>');
                var endDateTextBox = $('#<%=txtToDate.ClientID%>');
                startDateTextBox.datepicker({
                //minDate: 0,
                dateFormat: "dd/mm/yy",
                changeMonth: true,
                showAnim: 'slideDown',
                showOn: "focus",

                numberOfMonths: 1,
                separator:' ',
                onClose: function(dateText, inst) {
                    if (endDateTextBox.val() != '') {
                        var testStartDate = startDateTextBox.datepicker('getDate');
                        var testEndDate = endDateTextBox.datepicker('getDate');
                        if (testStartDate > testEndDate)
                            endDateTextBox.datepicker('setDate', testStartDate);
                        }
                        else {
                            //endDateTextBox.val(dateText);
                        }
                    },
                    onSelect: function (selectedDateTime){
                        endDateTextBox.datepicker('option', 'minDate', startDateTextBox.datepicker('getDate') );
                        }
                    });
                    endDateTextBox.datepicker({
                        //minDate: 0,
                        dateFormat: "dd/mm/yy",
                        changeMonth: true,
                        showAnim: 'slideDown',
                        showOn: "focus",

                        numberOfMonths: 1,
                        separator:' ',
                        onClose: function(dateText, inst) {
                            if (startDateTextBox.val() != '') {
                                var testStartDate = startDateTextBox.datepicker('getDate');
                                var testEndDate = endDateTextBox.datepicker('getDate');
                                if (testStartDate > testEndDate)
                                    startDateTextBox.datepicker('setDate', testEndDate);
                            }
                            else {
                                //startDateTextBox.val(dateText);
                            }
                        },
                        onSelect: function (selectedDateTime){
                            startDateTextBox.datepicker('option', 'maxDate', endDateTextBox.datepicker('getDate') );
                        }
                });
            }
 
Share this answer
 
Comments
santsho kumar 9-Aug-13 5:37am    
thank you sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900