I'm using this daterange picker https://github.com/dangrossman/bootstrap-daterangepicker
I initialize with this in scripts.js then call scripts.js in the footer of my site
$(function(){
if(jQuery().daterangepicker) {
// Open Left
$('.daterange.right').daterangepicker({
opens: 'left'
});
// Open Right - default
$('.daterange').daterangepicker();
// Report range
$('#reportrange').daterangepicker({
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
'Last 7 Days': [moment(), moment().add({ days: -6 })],
'Last 30 Days': [moment().add({ days: -29 }), moment()],
},
startDate: moment().subtract('days', 29),
endDate: moment()
},
function(start, end) {
console.log(start.format('MMMM d, YYYY'));
$('#reportrange #rangedate').html(start.format('MMMM d, YYYY') + ' - ' + end.format('MMMM d, YYYY'));
});
}
});
On my main page i've put
$(function(){
alert(start);
});
and I get Uncaught ReferenceError: start is not defined
Why is start not defined? How can I get that variable from the function(start,end) so I can use the value when the page loads? I know I can get the dates by parsing the html of the field with $('#rangedate').html(); but how can I use the variables instead?
Thanks