Speed up development with full-stack environments for every branch.

Learn More

How to set a default date in a input type date [jQuery, JavaScript, period, month, initial, value, html5, day and year]

Forked from How to use the jQuery $().ready function.

790 Runs 5714 Views 1240 Copies

HTML5 and Javascript

Saved

Saved

mbrasil 1

mbrasil
published 2 years ago

function standardPeriod(p) {
				var CurrentDate = new Date();
				CurrentDate.setMonth(CurrentDate.getMonth() + p);
				
				var day = CurrentDate.getDate();
				var month = CurrentDate.getMonth()+1;
				var year = CurrentDate.getFullYear();
				
				if (month < 10)
					month = "0" + month;
				if (day < 10)
					day = "0" + day;
				
				var today = year + "-" + month + "-" + day;
				
				return today;
}
/*  jQuery ready function. Specify a function to execute when the DOM is fully loaded.  */
$(document).ready(
  /* This is the function that will get executed after the DOM is fully loaded */
  function () {
			$('#initialdate').val(standardPeriod(-6));
			$('#lastdate').val(standardPeriod(6));
  }
);
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).