Skip to content

Instantly share code, notes, and snippets.

@steveafrost
Created August 8, 2017 22:19
Show Gist options
  • Save steveafrost/ca4c41e35d34727aed3c02fa6e70366b to your computer and use it in GitHub Desktop.
Save steveafrost/ca4c41e35d34727aed3c02fa6e70366b to your computer and use it in GitHub Desktop.
Add prev, current, and next month to Gravity Form select field
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var now = new Date(),
prev = monthNames[now.getMonth() - 1] + " " + now.getFullYear(),
current = monthNames[now.getMonth()] + " " + now.getFullYear(),
next = monthNames[now.getMonth() + 1] + " " + now.getFullYear(),
optionsField = $('.gfield_select'),
options = [prev, current, next];
optionsField.empty();
$.each(options, function (i, option) {
optionsField.append($('<option>', {
value: i,
text: option
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment