Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the selected Date from the calendar control?

Tags:

jquery

asp.net

Hai ,

I am creating a DatetimePicker User control. I just want to know how to get the selected date of the calendar (asp.net control) control using jQuery. I used this code, but it's wrong.

$(document).ready(function()  {
     $(".UserCalender").click(function () { 

     var a = $('.CalenderDiv:selected').text(); 
     alert(a);        
     });
 });

What's wrong with this?

like image 362
Vibin Jith Avatar asked Oct 15 '22 08:10

Vibin Jith


1 Answers

You won't be able to do like this. There is no :selected selector for an anchor tag. It works only for <option> elements. What you can do is to attach an event hanlder to each anchor ag and use the text() method. Something like

$("#Calendar1 a").click(function(){
   alert ( $(this).text() );
   return false;
});

But why do you want to do this. By doing like this you will get only the text inside the anchor tag and not the whole date. To get the whole date you will have to perform additional work.

If you want to manipulate the selected text then you can use any datepicker plugin from jQuery.

See jQuery UI Datepicker

like image 136
rahul Avatar answered Oct 18 '22 22:10

rahul