0

I am trying to get the time selected from SharePoint list and store it one variable. I have attached an image for reference, Can anyone help me with this?enter image description here

2 Answers 2

1

No need to use the jquery, you can do that using vanilla JS querySelector

var time =   document.querySelector("select[id='Scheduled_x0020_time_0c63521b-1292-45ae-a881-f85e14c83ca7_$DateTimeFieldDateHours'").value + ":" + document.querySelector("select[id='Scheduled_x0020_time_0c63521b-1292-45ae-a881-f85e14c83ca7_$DateTimeFieldDateMinutes'").value 
console.log(time);

Explanation,

The datetime field has two select controls to show the time value

  • DateTimeFieldDateHours for Hours
  • DateTimeFieldDateMinutes for Minutes

So you are trying to query the selector with the actual ID id=, or using contains id=^ then try to concatenate both values to get the desired value as shown below.

Output

enter image description here

1
  • Thank you for the answer, will try this and let you know. Commented Sep 13, 2018 at 13:21
1

Mohamed's code is right, if you want to use jQuery code, check the code below.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function(){
    var fieldName="Select Scheduled Departure Time";
    var fieldDateHours=$(".ms-standardheader:contains('"+fieldName+"')").closest("tr").find("select[id$='_$DateTimeFieldDateHours']").val();
    var fieldDateMinutes=$(".ms-standardheader:contains('"+fieldName+"')").closest("tr").find("select[id$='_$DateTimeFieldDateMinutes']").val();
    console.log(fieldDateHours+":"+fieldDateMinutes);
})
</script>
4
  • Thank you for the answer, will try this and let you know if its working. Commented Sep 13, 2018 at 13:21
  • This function does not get triggered , I want to use this function in the change.function(). Can I use this there? Commented Sep 13, 2018 at 19:10
  • It says Uncaught TypeError: $(...).closest is not a function. when I try to run the code which you have mentioned. Commented Sep 19, 2018 at 20:28
  • My api request accepts 24 hour format date and I have 12 hour format date like this 9:00 PM and I need it to be as 21:00. How can I do that here in jquery? Commented Sep 19, 2018 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.