Skip to content

Instantly share code, notes, and snippets.

@boonebgorges
Created October 23, 2019 19:06
Show Gist options
  • Save boonebgorges/7bf05fe2cd813eadc49a36493e0a6b46 to your computer and use it in GitHub Desktop.
Save boonebgorges/7bf05fe2cd813eadc49a36493e0a6b46 to your computer and use it in GitHub Desktop.
Default to the current date for a BP date profile field
$(document).ready(function(){
var $day_field = $('#field_511_day');
var $month_field = $('#field_511_month');
var $year_field = $('#field_511_year');
if ( ! $day_field.val().length && ! $month_field.val().length && ! $year_field.val().length ) {
var dateObj = new Date();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var monthNumber = months[ dateObj.getMonth() ];
$day_field.find('option[value=' + dateObj.getDate() + ']').attr('selected','selected');
$month_field.find('option[value=' + monthNumber + ']').attr('selected','selected');
$year_field.find('option[value=' + dateObj.getFullYear() + ']').attr('selected','selected');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment