Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created October 10, 2012 13:39
Show Gist options
  • Save netsi1964/3865708 to your computer and use it in GitHub Desktop.
Save netsi1964/3865708 to your computer and use it in GitHub Desktop.
javascript dynamicweb various
(function($, window, undefined){
// https://gist.github.com/3865708
function insertExtraYears(selectorYear, iYearFrom, iYearTo) {
var year = jQuery(selectorYear);
var html = year.html();
var ahtml = html.split('><');
var aextra = [ahtml[0]];
for(var y=iYearFrom; y<iYearTo; y++) {
aextra[aextra.length] ='<option value="'+y+'">'+y+'</option'
}
for(var i=1; i<ahtml.length; i++) {
aextra[aextra.length] = ahtml[i];
}
year.html(aextra.join('><'));
}
// Add extra dates to selectbox
insertExtraYears('#customBirthday_year', 1910, 1930);
var customBirthday = jQuery('#customBirthday').val().split('-');
if (customBirthday.length===3) {
var iYearPos = -1;
for(var i=0; i<customBirthday.length && iYearPos===-1; i++) {
if (customBirthday[i]>31) iYearPos = i;
};
var year = customBirthday[iYearPos];
if (year>0) {
customBirthday = new Date(customBirthday[2],customBirthday[1]-1,year);
jQuery('#customBirthday_year option[value="'+year+'"]').attr('selected','selected');
}
}
})(jQuery, window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment