JavaScript Tutorial – Dynamic Select Year List Script HTML Form Elements




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”

  1. 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>

  2. 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!

Leave a Reply