Get the Value of Datepicker on Change in Jquery

Get name of day OnChange of Jquery Datepicker

Javascript:

<script type="text/javascript">
$("#pickyDate").datepicker({onSelect: function(dateText){
var days = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu' ];
var selecteddate = new Date (dateText).getDay ();
var weekday = days[selecteddate];
$('#txt_daypk').val(weekday);
}
});
</script>

Fiddle:
https://jsfiddle.net/zcyjq9we/

JQuery Datepicker doesn't change input value

You are confusing the inline value attribute with the actual value that the input field contains.

By the attribute value, I mean the following:

<input id="deliveryTime" name="deliveryTime" type="text" value="08/05/2015 10:00">

The value attribute is value="08/05/2015 10:00". The value could be whatever date you picked that is entered into the input field.

So even if the attribute is value="08/05/2015 10:00", the input's actual value, meaning whatever text is in the input field, is the real value.

When you do enter a new value into your input and then use $('#deliveryTime').val() you will see that your new value is the actual value of the text inside the input field.

If you are keen on changing the attribute of your input field, which I find kind of ambiguous since val() already returns that value, then you need to do the following:

$('#deliveryTime').change(function(){
$(this).attr('value', $('#deliveryTime').val());
});

So "On each change of the deliveryTime, set the value attribute to the input value". Fiddle!

As I said, this is ambiguous. I would recommend just using $('#deliveryTime').val() to fulfill the same purpose.

Listening to onChange on a jQuery datepicker?

Use jquery on input alongside with the on change event

$('#datepicker').datepicker()
.on("input change", function (e) {
console.log("Date changed: ", e.target.value);
});

Fiddle



Related Topics



Leave a reply



Submit