Created
October 23, 2019 19:06
-
-
Save boonebgorges/7bf05fe2cd813eadc49a36493e0a6b46 to your computer and use it in GitHub Desktop.
Default to the current date for a BP date profile field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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