Tuesday, 17 June 2014

create date Month and year Dropdownlist using jquery

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Generate years for dropdown</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        var yearvalue = 100; // Change to whatever you want
        var currentyear = (new Date()).getFullYear();
        for (var i = 0; i <= yearvalue; i++) {
            var year = currentyear - i;
            $('<option>', { value: year, text: year }).appendTo("#ddl_year");
        }
    });
$(function () {
    var Dayvalue = 31; // Change to whatever you want
    var ddate = 0;
    for (var i = 1; i <= Dayvalue; i++) {
        if (i < 10) {
            ddate = "0" + i;
        }
        else {
            ddate = i;
        }
        $('<option>', { value: ddate, text: ddate }).appendTo("#ddl_Date");
    }
});
$(function () {
    var Monthvalue = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; // Change to whatever you want
    var monthval = "";
    for ( var m = 0; m < 12; m++) {

        monthval = Monthvalue[m];


        $('<option>', { value: monthval, text: monthval }).appendTo("#ddl_Month");
    }
});
</script>
</head>
<body>
<form id="form1">
<div>
Date:-<select id="ddl_Date"></select>
Month:-<select id="ddl_Month"></select>
Year:- <select id="ddl_year"></select>
</div>
</form>
</body>
</html>



No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...