This is a migrated thread and some comments may be shown as answers.

setting datepicker value

4 Answers 95 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nebras
Top achievements
Rank 1
Nebras asked on 02 Mar 2011, 03:46 PM
I know that I can read the datepicker value by :
var datepicker = $("#DatePicker").data('tDatePicker');
 var date = datepicker.value();


but i want to set the value by useing "words" such as "Today", "Last Week" and so on , how ?

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 02 Mar 2011, 04:05 PM
Hello Nebras,

Please refer to this online demo which demonstrates how to achieve such functionality.

Regards,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Nebras
Top achievements
Rank 1
answered on 02 Mar 2011, 04:18 PM
I know them but what I want is to make the "words" to be in a dropdownlist
which doesn't  has a "class" attribute to be used in this function

<% Html.Telerik().ScriptRegistrar().OnDocumentReady(
() => {%>     
   $(
'.humanReadableExamples a').click(function(e) {  
          e.preventDefault();         
               setTimeout($.proxy(
function() {   
             $(
'#DatePicker-input')  
              .focus()              
  .val($(
this).text());         
   },
this), 0);        });    <%}); %>

so I created a dropdownlist with :

<%=Html.Telerik().DropDownList()
           .Items(columns =>
           {
               columns.Add().Text("All").Value("All");
               columns.Add().Text("Today").Value("Today");
               columns.Add().Text("Last Week").Value("Last Week");
               columns.Add().Text("Last Month").Value("Last Month");
               columns.Add().Text("Last Year").Value("Last Year");
                 
           }
                 ).ClientEvents(c=>c.OnChange("OnChange"))
     .Name("fffff")
         %>

function OnChange(e) {
  
                if (e.value != "All") {
           
                    var datepicker = $("#DatePicker").data('tDatePicker');
  ????????     //datepicker.value() = e.value;
                   }
            }
</script>


any help please ??
0
Accepted
Rosen
Telerik team
answered on 02 Mar 2011, 04:58 PM
Nebras,

You may apply the same approach as shown in the demo, but instead using the links click event, you should use the dropDownList change event:

<script type="text/javascript">
     function OnChange(e) {
         if (e.value != "All") {
             $('#DatePicker-input')
                 .focus()
                 .val(e.value)
                 .trigger('change');
         }
     }
 </script>

 
Regards,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Nebras
Top achievements
Rank 1
answered on 02 Mar 2011, 05:31 PM
It works .. Many Thanks ..
Tags
Date/Time Pickers
Asked by
Nebras
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Nebras
Top achievements
Rank 1
Share this question
or