var apptHour = $('select[name="ctl00$m$g_29cbb5be_bcd6_4949_875d_8fad4732db9b$ctl00$ctl05$ctl09$ctl00$ctl00$ctl04$ctl00$ctl00$DateTimeField$DateTimeFieldDateHours"]');  
var endHour = $('select[name="ctl00$m$g_29cbb5be_bcd6_4949_875d_8fad4732db9b$ctl00$ctl05$ctl11$ctl00$ctl00$ctl04$ctl00$ctl00$DateTimeField$DateTimeFieldDateHours"]');

apptHour.blur(function() {

This copies the hour (when I select the Appointment Date: Hour and the End: Hour will copy it) and of course there is minute too.

but I am afraid the long name will change over time.

In javascript i can use the

var apptHour = $("label:contains('Appointment Date Hours')").next().val();
var endHour = $("label:contains('End Hours')").next().val();

for conditional expression but it won't work if i tried to copy using jQuery.

enter image description here

Is there a way to do it?


  • You should either use IDs that you generate to identify which objects on a page contain the variables you need to grab. Or you can figure out how sharepoint is generating those names and pass those into Javascript dynamically. – Danack May 5 '13 at 14:32

There is a variable added to every page with time controls by SharePoint, at least I think its on every page. It's named g_strDateTimeControlIDs .

It has a property for each time control, with this syntax:

SP + InternalFieldName

So for Appointment Date, if was named like that to start with the internal name would be Appointment_x0020_Date. To get the ID for the field in the g_strDateTimeControlIDs variable, you add the prefix SP to it:


Now that would give you the ID to the "main" date field, for the Hours part, just add that to your select statement:

var apptHour = $('#'+g_strDateTimeControlIDs["SPAppointment_x0020_Date"]+"Hours");  
var endHour = $('#'+g_strDateTimeControlIDs["SPStress_x0020_Lab_x0020_Time"]+"Hours");
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy