I am using the bootstrap datetimepicker and trying to save the date when the alert on the page pops up it is showing up as blank. Please help, if more information is needed please let me know. Both lines of code are on the same html.erb page
This is the script that I am using to set the date
<div class='input-group date' id='datetimepicker1'>
<!--Trying to figure out how to capture the data -->
<input type='text' data-date-format="MM/DD/YYYY" class="form-control" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
script I am trying to use to store the data
<script type="text/javascript">
$('#datetimepicker1').on('change', function() {
alert($('#datetimepicker1').val());
});
</script>
initialize datetimepicker
$(".datetimepicker1").datetimepicker({
endDate: new Date,
format: "yyyy-mm-dd",
autoclose: true,
minViewMode: 1,
todayBtn: "linked"
});
From whatever I could understand, you probably are looking for this!
$(document).ready(function (){
$('#myDate').datepicker({ format: 'yyyy-mm-dd'
});
$('#myDate').on('change', function() {
var x = $('#myDate').val();
//alert("value of date is "+ x);
//do some ajax call and put/post the date like,
$.ajax({
type: 'post',
url: 'http://yourUrl',
data: {"date": x}, //in case String is to be sent!
success: function(x) {
//do some stuff on success, you can go with callback implementation too
console.log(x);
},
error: function(err){
console.log(err);
}
})
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.