Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
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() {
       endHour.val($(this).val());
    });

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?

Thanks

share|improve this question
    
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
add comment

migrated from stackoverflow.com May 5 '13 at 14:32

This question came from our site for professional and enthusiast programmers.

1 Answer

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:

g_strDateTimeControlIDs["SPAppointment_x0020_Date"]

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");
share|improve this answer
add comment

Your Answer

 
discard

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