Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Hi In my application page i have a sharepoint datetime control. I am using jquery on text changed event to calculate the number of days and displaying in a text box. Now i want to fire the same event when date is changed. But it is not working can you please help me.

<SharePoint:DateTimeControl ID="TStartDate" runat="server" DateOnly="true" UseTimeZoneAdjustment="false" LocaleId="2057"/>
    <asp:TextBox ID="txtNoofDays" runat="server" Width="28px"></asp:TextBox>
     <font color="#c00000">The Calculated Due Date is:</font><asp:TextBox ID="Txtdailyweekly" runat="server" style="margin-top: 8px"></asp:TextBox>

jquery
(document).ready(function () {
$('#' + '<%=this.txtNoofDays.ClientID  %>').change(function calculateAdddays() {

            var datepicker = $('#' + '<%=this.TStartDate.Controls[0].ClientID%>').val();
            alert(datepicker);
            var dmy = datepicker.split("/")
            var joindate = new Date(
        parseInt(
            dmy[2], 10),
            parseInt(dmy[1], 10) - 1,
            parseInt(dmy[0], 10)
        );
            var alertdays = $('#' + '<%=this.txtNoofDays.ClientID%>').val();

            alert(alertdays);
            joindate.setDate(joindate.getDate() + parseInt(alertdays));
            var x = "";

            x = (
            ("0" + joindate.getDate()).slice(-2) + "/" +
            ("0" + (joindate.getMonth() + 1)).slice(-2) + "/" +
            joindate.getFullYear()
        );
            alert(x);
            $('#' + '<%=this.Txtdailyweekly.ClientID %>').val(x);
        })

        $('#' + '<%=this.TStartDate.Controls[0].ClientID%>').change(function () { 
calculateAdddays();
alert("eventfired"); });

});

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Where are you running that binding call? You are defining it but you aren't executing it. It looks like you're missing a $(document).ready(); statement that runs the binding code you created. I think in SharePoint the function is function pageLoad(){} for the "when the document is ready run this code" function. Standard jQuery $(document).ready() sometimes doesn't work with post-backs, etc.

Edit: I see a few problems with your code:

$('#' + '<%=this.txtNoofDays.ClientID  %>').change(function calculateAdddays(){...});
  1. You need to bind the change event to your element. You cannot just call change(). You need something like the following: $('element').bind('change', function(){});
  2. You are trying to define a function instead of create an anonymous function. If you wanted to call calculateAdddays() your code should be $('element').bind('change', function(){ calculateAdddays(); });
share|improve this answer
    
sorry i didnt post my entire jquery code. here –  sandy_9866141457 Jul 19 '13 at 7:04
    
i tried so many options i think sharepoint datepicker control change event is not working with java script .. can any one helkp me please –  sandy_9866141457 Jul 19 '13 at 13:21
    
DOes any one tried calling the sharepoint date time control id in jquery or java script.. kindly let me know please –  sandy_9866141457 Jul 21 '13 at 4:15
    
Have you tried using $().bind('change', function(){}) instead of '$().change(function(){})'? –  EHorodyski Jul 21 '13 at 21:00
    
yes i tried but still it is not triggering –  sandy_9866141457 Jul 22 '13 at 11:22

This article explains every scenario for the datetime picker control. I've used it without issue.

http://theway4ward.wordpress.com/2013/07/30/211/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.