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

[Solved] Attach OnChange handler from javascript

8 Answers 255 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.
Pavel Balas
Top achievements
Rank 1
Pavel Balas asked on 26 Mar 2012, 08:11 PM

Hi all,

is it possible to attach client event OnChange  from javascript code? Something like 

var datePicker = $("#DatePicker").data("tDatePicker");

datePicker.bind('onChange'function(e) {alert('onChange')} );

Thanks

Pavel


8 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 27 Mar 2012, 09:52 AM
Hello Pavel,

 
In order to achieve your goal you will need to bind the "valueChange" event:

var datePicker = $("#DatePicker").data("tDatePicker");
datePicker.bind('valueChange', function(e) {alert('onChange')} );

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Dipak
Top achievements
Rank 1
answered on 26 Apr 2012, 04:04 PM
<p><strong>Updates :</strong></p><p>This is my intranet website. if i access it through ip address its wrorking fine, but if i will access it with computer name let say , <a href="http://xzy/webapp/" rel="nofollow">http://xzy/webapp/</a> , it does not working.</p>Hi Georgi,

 i am making Telerik DatePicker dynamically through Partial View in asp.net MVC. Initially i have bind the event like .ClientEvents(events => events.OnChange("onChangeDatePicker")), but i found that if you loading controls dynamically you cann't do that way, you have to bind event dynamically through jQuery Event bubbling. i have below code works fine in my development envoiornment but after deployment on windows server 2008 it stop working in IE9. Its works fine with FF, Safari, Chrome. I have multiple datetime picker on one page.

Can you please help me in this?

$("document").ready(function ()
{
debugger;
var dtpickers = $("[Id^=dtt]");
for (i = 0; i < dtpickers.length; i++) {
if ($.browser.msie) {
$(dtpickers[i]).tDatePicker({
onChange: function () { onChangeDatePicker(this); }
});
}
else {
$(dtpickers[i]).tDatePicker({
onChange: function () { onChangeDatePicker(this); }
});
}
}
});
</script>

Updates :

This is my intranet website. if i access it through ip address its wrorking fine, but if i will access it with computer name let say , http://xzy/webapp/ , it does not working.

0
Dipak
Top achievements
Rank 1
answered on 26 Apr 2012, 06:10 PM
Its resolved now. It was issue with Compatibility view, by default with Intranet website it is On. so i off it and its work fine with me. I believe jQuery Delegated Events is not compatible with previous version of IE.
0
Deepak
Top achievements
Rank 1
answered on 08 May 2012, 10:23 PM
Do I have to call any other method after attaching the Event like this?  It does not seem to be working for me.

Thanks.
0
Dipak
Top achievements
Rank 1
answered on 09 May 2012, 12:50 AM
No its not. in my code i have called javascript function "onChangeDatePicker(this);" in that i am doing ajax call to do some of my stuff. if you can show me your code with little more details then i can look into it.

You can write any javascript function like this.
onChange: function () { alert('xyz'); }
0
Deepak
Top achievements
Rank 1
answered on 09 May 2012, 02:52 AM
Here's my code.  This is within a Grid's onEdit event where one of the columns is a DatePicker:

Create.StartDatePicker = $(e.form).find('#StartDate').data('tDatePicker'); 
Create.StartDatePicker({ onChange: function () { alert('hi'); } }); 
0
Deepak
Top achievements
Rank 1
answered on 09 May 2012, 03:09 AM
Finally after digging into Telerik's source code, I figured that this works (don't refer to data('tDatePicker')):
Create.StartDatePicker = $(e.form).find('#StartDate'); 
Create.StartDatePicker.bind('valueChange', function (e) { alert('hi'); }); 

0
Arjun
Top achievements
Rank 1
answered on 07 Mar 2013, 10:16 AM
Thanks Deepak. Your solution worked like a charm.

Adding the code for reference.

Create.StartDatePicker = $(e.form).find('#StartDate');
 
Create.StartDatePicker.bind('valueChange', function (e) { alert('hi'); });
Tags
Date/Time Pickers
Asked by
Pavel Balas
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Dipak
Top achievements
Rank 1
Deepak
Top achievements
Rank 1
Arjun
Top achievements
Rank 1
Share this question
or