This is pretty basic stuff, but I cant figure this out. I'm using jQuery's DatePicker. My goal is to display some text with the selected date. If the user chooses a date passed today's date, I'm changing the text to too late. When the user re-chooses a future date, I want to set the divs text to something and add the selected date inside a span which sits inside this div. All works except the future date is not appearing. Why?
What is the best practice when it comes to changing content of some element? Can I use jQuerys remove and then append?
HTML:
<p>Date: <input id="datepicker" type="text"></p>
<p id="we_will_start">starting at: <span id="start_date"></span></p>
JQUERY:
$('#datepicker').datepicker({
onSelect: function(dateText, inst){
var dateAsString = dateText;
var selectedDateAsObject = $(this).datepicker('getDate');
console.log("date object=" + new Date+ " jquery date=" + selectedDateAsObject);
console.log(dateAsString);
if(selectedDateAsObject < new Date){
console.log("bad date. cant start yesterday fool");
$("#we_will_start").text("too late!");
}else{
$("#we_will_start").text("will start at ");
document.getElementById("start_date").innerHTML = dateAsString;
}
}
});