1

I want to check whether a Sharepoint datetime control is empty or not. How can I do this using jQuery?

0

If you are using SharePoint's OOB Date time control, I am assuming below would be the mark up.

<SharePointWebControls:DateTimeControl ID = "StartDate" runat = "server"></SharePointWebControls:DateTimeControl>

So now in order to validate this field we can use jQuery.

1. Understand how this SharePoint control is rendered in browser. It will be something like below.

<input name="ctl00$PlaceHolderMain$StartDate$StartDateDate" class="ms-input" id="ctl00_PlaceHolderMain_StartDate_StartDateDate" type="text" maxlength="45" autopostback="0">

2. Point to note is the name of the control is rendered as StartDateDate. So we can utilise this and get value of the control using jQuery.

3. Store the value in a variable and check for empty.

var startDateValue = jQuery("input[name$='StartDateDate']").val().trim()
//Check for empty 
//Check for Start Date
if (startDateValue == '') {
    alert('Empty');
}
else {
    alert('Not Empty');
}

I hope this helps.

| improve this answer | |
  • Actually I am using this Control <sharepoint:datetimecontrol id="dtfrom" dateonly="true" runat="server"></sharepoint:datetimecontrol> – Ishani May 6 '15 at 6:21
  • I guess it should work. Can you see what's the name and id you get for this control in browser using F12 developer tool.? – Asad Refai May 6 '15 at 6:27
  • Np. Happy to help :) – Asad Refai May 6 '15 at 6:40

Your Answer

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

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