[Solved] jQuery add date to input, but only if it’s empty [closed]


DEMO

var months = new Array(12);
months[0] = "Jan";
months[1] = "Feb";
months[2] = "Mar";
months[3] = "Apr";
months[4] = "May";
months[5] = "Jun";
months[6] = "Jul";
months[7] = "Aug";
months[8] = "Sep";
months[9] = "Oct";
months[10] = "Nov";
months[11] = "Dec";
var d = new Date();

var month = d.getMonth();

if($('#NewsDay').val() == "") {
    $('#NewsDay').val(d.getDate());
}
if($('#NewsMonth').val() == "") {
    $('#NewsMonth').val(months[month]);
}

A bit crude but works. Copied code from one of my previous answers. I say crude because it doesn’t consider timezones & day light savings and any other offsets.

3

solved jQuery add date to input, but only if it’s empty [closed]