Here is a simple and quick jQuery plugin that will split the MySql date format values of an form element into select form elements.
Html element:
Call the plugin:
$(function() { $('#birth_date').birthDate(); });
And the plugin:
/** * Simple plugin that converts an hidden html element * that has a MySql date format value into select elements * * @author Calin Rada*/ $.fn.birthDate = function( options ) { if($(this).length == 0) { return false; } var settings = $.extend({ dateFormat: "d-m-Y" }, options ); var currentDate = new Date(); var minYear = currentDate.getFullYear() - 110; $('').insertAfter($(this)); if($('#birthDatePlugin').length > 0) { var dates = $('#birth_date').val().split('-'); var year = dates[0]; var month = dates[1]; var day = dates[2]; var content = ''; var yearContent = '
And the result:
If this helped you, i’m glad đ