Reputation: 1011
I need to get the value of datepicker
on change
, But it is returning undefined
.
HTML :
<input id="#return" name="start" class="date-pick form-control" value="" data-date-format="dd/mm/yyyy" type="text" />
JS :
$('input.date-pick').datepicker().on('changeDate', function (ev) {
var firstDate = $('#return').val();
alert(firstDate);
});
Upvotes: 1
Views: 38333
Reputation: 21
$("#datepickerID").on('change', function() {
dateVar = $("this").val();
}
You can get value by calling function when onchange
event occur. Then, after you can store that value, alert it or print it on console.
Upvotes: 0
Reputation: 1
You can also get the value directly from your onchange
event:
onChange="variable=$(this).val();"
Upvotes: 0
Reputation: 1815
you can easily do with below code:
$(".date-pick").on('change', function(event) {
event.preventDefault();
alert(this.value);
/* Act on the event */
});
Upvotes: 3
Reputation: 4987
Your date field
<input id="thedate" type="text" class="date-pick"/>
And if you using bootstrap datepicker then add this script code
$(function() {
$('.date-pick').datepicker({
dateFormat: 'dd-mm-yy',
onSelect: function(dateText, inst) {
alert(dateText);
}
});
});
Here is the fiddle
http://jsfiddle.net/s1L5pjpb/1/
Upvotes: 0
Reputation: 67505
You could also use regular event change
:
$('input.date-pick').datepicker().on('change', function (ev) {
var firstDate = $(this).val();
alert(firstDate);
});
Hope this helps.
Upvotes: 7
Reputation: 8101
Use onSelect
event and you can get selected value with in dateText
variable
$('.date-pick').datepicker({
onSelect: function(dateText, inst) {
alert(dateText);
}
});
Upvotes: 4