Multi-date Datepicker Example

by BeePositive

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<select id = "user_time_zone">

<option>Select Types </option>
<option value = "Single Date">Single Date</option>
<option value = "Range of Dates">Range of Dates</option>
</select>
<br><br>

<div id='sd'>Single Date:<input type="text" id="singleDate" name="singleDate" /></div>

<div id='rd'><div class="input-group date form-group" id="rangeDates">
    <input type="text" class="form-control" id="rangeDates" name="tpoc_start_date" placeholder="Select days" required />
    <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i><span class="count"></span></span>
    </div></div>

JavaScript

$('#user_time_zone').on('change', function() {
 dateCalender = $(this).val();
  if (dateCalender == 'Single Date') {
    $('#sd').show();
    $('#rd').hide();

  } else if (dateCalender == 'Range of Dates') {
    $('#rd').show();	
    $('#sd').hide();       
  } else if (dateCalender == 'Select Types') {
    $('#rd').hide();	
    $('#sd').hide();       
  }
});


$('#rd').hide();	
$('#sd').hide(); 


//date range picker for range date
$(document).ready(function() {
    $('#rangeDates').datepicker({
        startDate: new Date(),
        multidate: true,
        format: "dd/mm/yyyy",
        daysOfWeekHighlighted: "5,6",
        datesDisabled: ['31/08/2017'],
        language: 'en'
    }).on('changeDate', function(e) {
        // `e` here contains the extra attributes
        $(this).find('.input-group-addon .count').text(' ' + e.dates.length);
    });
});