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

Call javascript function on OnChange event

4 Answers 128 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.
Luis Velez
Top achievements
Rank 1
Luis Velez asked on 22 Apr 2010, 08:40 PM
What's the best way to call a javascript function that takes a couple of parameters when the date is changed?

I have a function in my .js file:
function AddNumbers(a,b){
   return a+b;
}

I've tried:
<%= Html.Telerik().DatePicker()
   .Name("myID")
   .ClientEvents(events => {events.OnChange("AddNumbers(1,2)");})
%>

and

<%= Html.Telerik().DatePicker()
   .Name("BusinessTaxReceipt.LicenseExpirationDate")
   .InputHtmlAttributes(new { onchange = "AddNumbers(1,2)" })
%>

I even tried wiring up a jQuery blur event to the control, but it seems to be firing at the wrong time (usually when a date is selected and before the textbox value is actually changed), so in the blur event method when i get the value it gets the value in textbox which hasn't been updated at that point.

Any ideas? Thanks.
Ozzie

4 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 23 Apr 2010, 09:11 AM
Hello Luis,

You can try wire event handler and call your method from it:
<%= Html.Telerik().DatePicker()
   .Name("myID")
   .ClientEvents(events => {events.OnChange("onChange");})
%>
function onChange(e){
//your function.
}

Sincerely yours,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Luis Velez
Top achievements
Rank 1
answered on 23 Apr 2010, 06:27 PM
Thanks Georgi. So it's best to only use the built in event handler.

Hooking jQuery events to them when the page loads, like 'change' and 'blur', don't fire when expected.



0
Rafael
Top achievements
Rank 1
answered on 14 Feb 2011, 02:46 PM
I am using 2010.3.1318
But code above calls JS error
What's wrong?
0
Rafael
Top achievements
Rank 1
answered on 28 Mar 2011, 03:34 PM
Please advise how to refer to editing row in OnChange script to set End date when I change Start date? 
I use DatePicker is act as editor for Start and End columns
Tags
Date/Time Pickers
Asked by
Luis Velez
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Luis Velez
Top achievements
Rank 1
Rafael
Top achievements
Rank 1
Share this question
or