I want to check whether a Sharepoint datetime control is empty or not. How can I do this using jQuery?
1 Answer
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.
-
Actually I am using this Control <sharepoint:datetimecontrol id="dtfrom" dateonly="true" runat="server"></sharepoint:datetimecontrol>– IshaniMay 6, 2015 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.? May 6, 2015 at 6:27
-