1

I am doing some work in .net technology using MVC 4.0 with VB language.

I have dropdownlist that has a set of years from 2006 to running year. I want to set the selected year from dropdownlist to datepicker so I can have that year specific months and days and I have done following changes in datepicker.

 $('input').filter('.datepickerHoliday').datepicker({
                            changeMonth: true,
                            changeYear: false,
                            showYear: false,
                            dateFormat: 'mm/dd/' + yr,
                        });

How can I do this?

Mahavirsinh Padhiyar
  • 1,299
  • 11
  • 33
  • Where you want to display dropdown - inside your datepicker or outside. http://stackoverflow.com/questions/13865218/jquery-ui-datepicker-set-year-range-dropdown-to-100-years http://jqueryui.com/datepicker/#dropdown-month-year – Vinod Mar 31 '15 at 05:51
  • Dropdown is displayed outside. Actually I am taking year from dropdownlist and set it in datepicker (yr) as dateFormat but I am not getting the months and days for that specific year that I have selected in dropdownlist tht's why I have to set year in datepicker that I have selected in dropdown. How can I do that? – Mahavirsinh Padhiyar Mar 31 '15 at 05:56
  • @MahavirsinhPadhiyar Are you using jQuery ui datepicker? – malkam Mar 31 '15 at 06:10
  • Yes I am using JQuery ui. – Mahavirsinh Padhiyar Mar 31 '15 at 06:14

2 Answers2

2

This might do the trick. This is an basic you can build top of it.

var myDate = new Date();
var prettyDate = 01 + '/' + 01 + '/' + 'your selected dropdownlist year'
$("#date_pretty").val(prettyDate);

here is an link which gives you what you need :

Link

Link

Community
  • 1
  • 1
Vinod
  • 596
  • 2
  • 10
  • 28
1
var yr = $('#ddlYear').val();
var beforeDate = '01/01/' + yr;
var myDate = new Date(beforeDate);

$('input').filter('.datepicker').datepicker({
                   changeMonth: true
                   });
$('input').filter('.datepicker').datepicker("setDate", myDate);

so I got my selected year's date means year specific months and days.

Mahavirsinh Padhiyar
  • 1,299
  • 11
  • 33