I came up with a small issue, I am trying to come up with a way to fix it.
Basically what I want to do is take 18 years off the year ie: 2011 which returns 1993, and generate a drop down option for a user to select any year before that.
Basically they have to show that they are over the legal age of 18.
var minOffset = 18,
maxOffset = 100;
var thisYear = new Date().getFullYear();
var select = $('<select>');
for (var i = minOffset; i <= maxOffset; i++) {
var year = thisYear - i;
$('<option>', { value: year, text: year }).appendTo(select);
}
select.appendTo('body');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Demo: http://jsfiddle.net/DhpBg/.
var minOffset = 0, maxOffset = 100; // Change to whatever you want // minOffset = 0 for current year
var thisYear = (new Date()).getFullYear();
var m_names = ['January', 'February', 'March','April', 'May', 'June', 'July','August', 'September', 'October','November', 'December'];
var month = 0 // month = (new Date()).getMonth(); // for cuurent month
for (var j = month; j <= 11; j++) {var months = m_names[ 0 + j].slice( 0, 3 ); $('<option>', {value: months, text: months}).appendTo(".month"); }
for (var i = minOffset; i <= maxOffset; i++) { var year = thisYear + i; $('<option>', {value: year, text: year}).appendTo(".year");}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select class="year">
</select>
<select class="month">
</select>
better solution for month and year by jquery
www.jsfiddle.net/sudharshanreddyjanike/byvotshz/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With