Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iMsIdZz's avatar

Datepicker not working laravel 5.2

Here is my form

    <div class="form-group{{ $errors->has('DOB') ? ' has-error' : '' }}">
                        <label class="col-md-4 control-label">Date of Birth</label>

                        <div class="col-md-6">
                            <input type="text" class="datepicker" name="DOB" value="{{ old('DOB') }}">

                            @if ($errors->has('DOB'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('DOB') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

i already download and linked http://www.eyecon.ro/bootstrap-datepicker/ this datepicker

My css File is

    <link rel="stylesheet" type="text/css" href="{{ url('datepicker/css/datepicker.css') }}">
    

My Script file is

    <script src="{{ url('datepicker/js/bootstrap-datepicker.js') }}"></script>
        <script>
        $ (function() {
         $('.datepicker').datepicker();
        });
     </script>
0 likes
8 replies
willvincent's avatar

The script that bootstraps the datepicker should be wrapped in a document ready.

<script>
  $(document).ready(function() {
    $('.datepicker').datepicker();
  });
</script>

Otherwise it could try to fire before the dom is rendered, before the element exists.

1 like
jlrdw's avatar

Field to datepick make sure it has an id

<td><input type="text" name="transdate" id="transdatea" value="" size="14"></td>

code to date pick, put in an image to click on

$(document).ready(function () {

$("#transdate").datepicker({
            showOn: "button",
            buttonImage: "/checkbook/public/overcast/images/calendar19.gif",  // put in an image to click on
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd",
            changeMonth: true,
            changeYear: true
        });
    });  

There are examples of this on the jquery ui site, with example source code also.
Let me know and I'll post a video of this in action.

tykus's avatar

@iMsIdZz it might help if you gave some indication of what errors you are getting - there is probably something in the console if you have followed @willvincent advice

iMsIdZz's avatar

Still Not Working it anymore i have downloaded and installed new package called "eternicode/bootstrap-datepicker" how i use this

jlrdw's avatar

Did you even try to comment out everything and just do an alert

alert("here");

Your JavaScript may not even be loaded properly, you need to check this stuff.

iMsIdZz's avatar

ooppsss problem found was from jquery i forgot to add jquery.js

and the script i stolen from datepicker site haha

iMsIdZz's avatar
iMsIdZz
OP
Best Answer
Level 4

My forum

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                        <label class="col-md-4 control-label">Date of Birth</label>

                        <div class="col-md-6">
                            <input type="text" class="span2" value="02-16-2012" id="dp1" value="{{ old('email') }}">

                            @if ($errors->has('email'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('email') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div> 

<script>

        if (top.location != location) {
        top.location.href = document.location.href ;
     }
    $(function(){
        window.prettyPrint && prettyPrint();
        $('#dp1').datepicker({
            format: 'mm-dd-yyyy'
        });
        $('#dp2').datepicker();
        $('#dp3').datepicker();
        $('#dp3').datepicker();
        $('#dpYears').datepicker();
        $('#dpMonths').datepicker();
        
        
        var startDate = new Date(2012,1,20);
        var endDate = new Date(2012,1,25);
        $('#dp4').datepicker()
            .on('changeDate', function(ev){
                if (ev.date.valueOf() > endDate.valueOf()){
                    $('#alert').show().find('strong').text('The start date can not be greater then the end date');
                } else {
                    $('#alert').hide();
                    startDate = new Date(ev.date);
                    $('#startDate').text($('#dp4').data('date'));
                }
                $('#dp4').datepicker('hide');
            });
        $('#dp5').datepicker()
            .on('changeDate', function(ev){
                if (ev.date.valueOf() < startDate.valueOf()){
                    $('#alert').show().find('strong').text('The end date can not be less then the start date');
                } else {
                    $('#alert').hide();
                    endDate = new Date(ev.date);
                    $('#endDate').text($('#dp5').data('date'));
                }
                $('#dp5').datepicker('hide');
            });

    // disabling dates
    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);

    var checkin = $('#dpd1').datepicker({
      onRender: function(date) {
        return date.valueOf() < now.valueOf() ? 'disabled' : '';
      }
    }).on('changeDate', function(ev) {
      if (ev.date.valueOf() > checkout.date.valueOf()) {
        var newDate = new Date(ev.date)
        newDate.setDate(newDate.getDate() + 1);
        checkout.setValue(newDate);
      }
      checkin.hide();
      $('#dpd2')[0].focus();
    }).data('datepicker');
    var checkout = $('#dpd2').datepicker({
      onRender: function(date) {
        return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
      }
    }).on('changeDate', function(ev) {
      checkout.hide();
    }).data('datepicker');
    });
</script>
<script src="js/bootstrap-datepicker.js"></script>

Please or to participate in this conversation.