(function( $ ) { 'use strict'; $.fn.initWhenBox = function(options) { var settings = $.extend({ from_date_id: undefined, to_date_id: undefined, from_time_id: undefined, to_time_id: undefined }, options); var box = $(this); var from_date = $('#' + settings.from_date_id, box); if (!from_date.length) { alert('From Date Element was not found.'); return; } var to_date = $('#' + settings.to_date_id, box); if (!to_date.length) { alert('To Date Element was not found.'); return; } var on_from_date_change = function () { to_date.prop('min', this.value); }; var on_to_date_change = function () { from_date.prop('max', this.value); }; from_date.on('change', on_from_date_change); to_date.on('change', on_to_date_change); }; })( jQuery );