How Do I Pass The Date Range Selected In The Daterangepicker To A Variable Or Back To My Input Textbox In Javascript?
My javascript below using preset ranges for DateRangePicker - I need to pass the selected start and end dates to two variables call StartDate and EndDate or pass it back to my Logi
Solution 1:
$("#inpDatePicker").val()
will return an object with start
and end
. You can listen to your $("#inpDatePicker")
's change
event to see when to get the values.
$("#inpDatePicker").daterangepicker({
onChange: function() {
StartDate = $("#inpDatePicker").val().start;
EndDate = $("#inpDatePicker").val().end;
}
}
Solution 2:
JQuery Declaration:
$("#inpDatePicker").daterangepicker({...})
Event Trigger (This goes in after an event is fired):
var range = $("#inpDatePicker").daterangepicker("getRange");
$("#range_start").val(range['start']);
$("#range_end").val(range['end']);
HTML:
<input id="inpDatePicker" name="inpDatePicker" type="text">
<input type="hidden" name="range_start" id="range_start">
<input type="hidden" name="range_end" id="range_end">
Post a Comment for "How Do I Pass The Date Range Selected In The Daterangepicker To A Variable Or Back To My Input Textbox In Javascript?"