Lesson Code: http://www.developphp.com/video/JavaScript/Dynamic-Select-Year-List-Script-HTML-Form-Elements
PHP Version: http://www.youtube.com/watch?v=_vEyFYj09GE
Learn to program dynamic year select lists in HTML forms to avoid the need to write up to 100 lines in your HTML. The JavaScript loop will write the options for you in a for loop. We can do this easily because years are numeric and incremental.
Original source
21 responses to “JavaScript Tutorial – Dynamic Select Year List Script HTML Form Elements”
If i have a button/radio button and after click on button the dynamic year list going to execute .so ,how to do that ?? please help me ..
I'd write it like this, to give the user a blank date up top, and to start from 2015-1900. It makes it easy for users to find their birth year…(unless they type it).
<select name="year" id="year">
<option value=""> </option>
<script>
var myDate = new Date();
var year = myDate.getFullYear();
for(var i = year; i > 1899; i–){
document.write('<option value="'+i+'">'+i+'</option>');
}
</script>
</select>
Good
Nice example but for this scenario I would just use php instead of javascript. The syntax would be very similar.
What if you have Lets say a Music List an Artist list and a Song List. How do you link them together to choose the music the artist and the song? Would Love to have an answer please. Thank you.
As a programmer you can die? Pretty sure I'm already dead. On the inside. =)
He already mentioned it in the video. You can do it this way: var date = new Date(); var year = date.getFullYear(); and then in FOR loop go for(var i=1900;i <= year; i++). Hope I helped.
So wait, you still have to update it each year?
Adam, fabulous! It's because of you I am now at university studying Digital Media, Web Software & Software/Gaming Design! It was by watching your videos and following the first web intersect series I learned PHP, you honestly are amazing; you've literally made my ambition of career possible. Thanks!
One thing, how do you order that? To show the latest year, meaning start from 2013 and not 1900.
thanks man nice work
Niiiice 😀 awesome tricks :3
Hello Adam sorry for insisting can you please provide to us a tutorial about a modal window without using any plugin?
I will make another PHP version now. Good point. But not many people would disable JavaScript cuz they would disable almost everything cool/interactive on the web today.
Would there be any advantage to using JavaScript over PHP. If a user has JavaScript disabled this would not work, however it would with PHP.
Thanks for the tutorial 🙂 I
Thanks brother
that's slick!
Learnt something new once again 😀 thanks Adam!
No problem buddy
Another great video! Thank you Adam!