'How to set jquery datepicker value to null using jquery
I need to set the value of datepicker to null using jQuery.
I tried
$.datepicker._clearDate(this);
and
$( "#datepicker" ).datepicker().val('')
but not working. I'm using jQuery's datepicker plugin.
Solution 1:[1]
Just assign null
to input field
$("#datepickerinputid").val('');
Solution 2:[2]
Use the jquery.datetimepicker.full.min.js
not the jquery.datetimepicker.min.js
Solution 3:[3]
There are several ways to achieve this
1.Using input selector by name
$("input[name='your_date_picker_name']", this).val("");
2.If your date picker is associated with a form
$("input[name='your_date_picker_name']", $('#form_id')).val("");
3.Or simply try this
$( "#your_date_picker_name" ).datepicker('setDate','');
Solution 4:[4]
<input type="text" name="datefilter" value="" />
<script type="text/javascript">
$(function() {
$('input[name="datefilter"]').daterangepicker({
autoUpdateInput: false,
locale: {
cancelLabel: 'Clear'
}
});
$('input[name="datefilter"]').on('apply.daterangepicker', function(ev, picker) {
$(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
});
$('input[name="datefilter"]').on('cancel.daterangepicker', function(ev, picker) {
$(this).val('');
});
});
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | linktoahref |
Solution 2 | linktoahref |
Solution 3 | |
Solution 4 | Tiago |