0

I have a code of calender in java script. Its in working, want it to automaticaly select current date .its Possible.

Javascript code:

<script>
    $(function() {
    $( "#interview_on" ).datepicker();
    });
</script>

Custom Form:

<form method="POST" action="/interviewvalue/" class="form-horizontal" id="userform" name="uform" enctype="multipart/form-data">{% csrf_token %}
<div class="control-group formSep">
    <label for="u_fname" class="control-label">Interview On</label>
    <div class="controls">
        <input type="text" class="input-xlarge" name="interviewon" id="interview_on" readonly="true" />
    </div>
</div>
<div class="control-group">
    <div class="controls">
        <button class="btn btn-gebo" type="submit" name="asubmit">Submit</button>
        <input type="reset" name="reset" value="Cancel" class="btn btn-gebo" />
    </div>
</div>

4

2 回答 2

1

You can restrict the selectable range of the Datepicker like this

 $( "#datepicker" ).datepicker({ 
    minDate: -10D, maxDate: "+10D" 
 });

which shows 10 days of the past and 10 days of the future.

You find a detailed description here http://jqueryui.com/datepicker/#min-max

于 2013-09-12T07:15:43.587 回答
1

If you want the actual field to be filled with the current date just use the setDate after creating the datepicker. Like this

<script type="text/javascript">
    $(function() {
        $("#interview_on").datepicker();
        $("#interview_on").datepicker('setDate', new Date());
    });
</script>

In case you want to restrict the selectable dates to only today, Tobo's suggestion is correct, just do

<script type="text/javascript">
    $(function() {
        $("#interview_on").datepicker({minDate: 0, maxDate: 0});
        $("#interview_on").datepicker('setDate', new Date());
    });
</script>
于 2013-09-12T09:09:57.343 回答