none
javascript/jquery to update a datetime control RRS feed

  • Question

  • I have problem to get date on the date time control on the even of date changed in javascipt/jquery. Please see the follows:

    <SharePoint:DateTimeControl ID="dtStartTime1" runat="server" AutoPostBack="true" OnLoad="dtStartTime1_Load" DateOnly="False" />

    <script src="../_layouts/15/jquery.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function () {       

            var date1 = getTagFromIdentifierAndTitle('input', '', 'ctl00_ctl41_g_dc9f33b1_b254_4612_a4ca_f1734ba60536_dtStartTime1_dtStartTime1Date');

            var date2 = getTagFromIdentifierAndTitle('input', '', 'ctl00_ctl41_g_dc9f33b1_b254_4612_a4ca_f1734ba60536_dtEndTime1_dtEndTime1Date');

            date1.onchange=function() {       

                alert('date field changed');

            };

            function getTagFromIdentifierAndTitle(tagName, identifier, id) {

                var len = identifier.length;

                var tags = document.getElementsByTagName(tagName);

                for (var i = 0; i < tags.length; i++) {

                    var tempString = tags[i].id;

                    if (tags[i].id == id && (identifier == '' || tempString.indexOf(identifier) == tempString.length - len)) {

                       return tags[i];

                    }

                }

                return null;

            }

        });   

    </script>

    It get the control. But it will not sent the control it get back to the main script so the alert is not run? Please see if you have a though what the problem can be. Many thanks.


    • Edited by eg10013 Thursday, April 20, 2017 8:21 PM
    Thursday, April 20, 2017 8:17 PM

Answers

  • Hi,

    Sorry for the mistake. I have updated the link in my previous post, please check it.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by eg10013 Thursday, April 27, 2017 6:25 PM
    Thursday, April 27, 2017 7:27 AM
    Moderator

All replies

  • Hi,

    From your script, it seems that you are passing null values as identifier to the function getTagFromIdentifierAndTitle, and the function would return null if the passed identifier value is null.

    Could you please verify the values you passed to the function getTagFromIdentifierAndTitle?

    Best Regards,

    Victoria  


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, April 21, 2017 11:11 AM
    Moderator
  • Hi,

    Please check below articles for more details:

    https://social.technet.microsoft.com/Forums/sharepoint/en-US/61e8de17-eca5-4eeb-be1d-99daff6fc34b/read-sharepoint-date-time-control-in-jqueryjavascript?forum=sharepointdevelopmentprevious

    https://social.technet.microsoft.com/Forums/sharepoint/en-US/91ad094e-099b-4917-810f-eec96745af64/javascript-to-get-sharepoint-datetimecontrol-selecteddate-value?forum=sharepointcustomizationlegacy

    http://www.balestra.be/2012/02/get-time-from-a-sharepoint-date-time-field-via-jquery.html

    http://stackoverflow.com/questions/26782795/tracking-the-date-time-changes-in-datepicker-control-using-javascript-jquery


    Thanks, Amit Kumar, LinkedIn Profile ** My Blog
    Please click "Mark As Answer" if this post solves your problem or "Vote As Helpful" if it was useful

    Friday, April 21, 2017 12:21 PM
  • I have tried pass the value to the function which does not make a different because identifier (identifier == '' || tempString.indexOf(identifier) == tempString.length - len).

    Thanks for your response.

    Friday, April 21, 2017 7:32 PM
  • I have tried all these methods. It seems do not work form me. I do not know what is the different. For example the last link. It almost the same code I used except I have to use the control's [id] instead of [title] because I do not/cannot have a title in the control (I am using SharePoint 2013)
    Friday, April 21, 2017 7:38 PM
  • Hi,

    Please use the demo in the link below to track the change event in a date picker.

    http://sharepointplays.blogspot.sg/2013/08/javascript-for-datetime-picker.html

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Wednesday, April 26, 2017 6:49 AM
    Moderator
  • Hello Victoria, I read the demo you provided. It seems to me it is related to "people picker", not for a "date time controller"? Thanks
    Wednesday, April 26, 2017 2:29 PM
  • Hi,

    Sorry for the mistake. I have updated the link in my previous post, please check it.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by eg10013 Thursday, April 27, 2017 6:25 PM
    Thursday, April 27, 2017 7:27 AM
    Moderator
  • Thank you Victoria.
    Thursday, April 27, 2017 6:26 PM