jQuery/JavaScript validation controls
<p>I have a form on a sharepoint site and want some fields to be required fields (datetime picker etc.).
To make some other fields visible/hidden and also add a red * after required field titles I use (example) :</p>

<pre><code>//Strategic Priority
$('nobr:contains("Strategic Priority")').closest('tr').show();
$('nobr:contains("Strategic Priority")').html("Strategic Priority &lt;span class=\"validate\"&gt; *&lt;/span&gt;");

//Performance Measure
$('nobr:contains("Performance Measure")').closest('tr').hide();

//Start Date   
$('nobr:contains("Start Date")').closest('tr').show();
$('nobr:contains("Start Date")').html("Start Date &lt;span class=\"validate\"&gt; *&lt;/span&gt;");
</code></pre>

<p>What is the best way to validate required field elements when the user hits a submit button?</p>

<p>The HTML looks something like :</p>

<pre><code>&lt;td class="ms-formbody" valign="top" width="400px"&gt;
  &lt;!-- FieldName="Target Date"
    FieldInternalName="DueDate"
    FieldType="SPFieldDateTime"
    --&gt;
   &lt;span dir="none"&gt;
  &lt;script language="javascript"&gt;g_strDateTimeControlIDs["SPDueDate"] = "ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl04_ctl00_ctl00_DateTimeField_DateTimeFieldDate";&lt;/script&gt;

    &lt;table&gt;&lt;tbody&gt;&lt;tr&gt;
    &lt;td class="ms-dtinput"&gt;
    &lt;label for="ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl04_ctl00_ctl00_DateTimeField_DateTimeFieldDate" style="display: none;"&gt;Target Date Date&lt;/label&gt;
    &lt;input name="ctl00$m$g_c6ae303a_6013_4adb_8057_63a214bcfd24$ctl00$ctl04$ctl10$ctl00$ctl00$ctl04$ctl00$ctl00$DateTimeField$DateTimeFieldDate" maxlength="45" id="ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl04_ctl00_ctl00_DateTimeField_DateTimeFieldDate" title="Target Date" class="ms-input" autopostback="0" type="text"&gt;&lt;/td&gt;
</code></pre>

<p>Generated HTML for button:</p>

<pre><code>&lt;td class="ms-toolbar" nowrap="true"&gt;

  &lt;table width="100%" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td width="100%" align="right" nowrap="nowrap"&gt;
   &lt;input name="ctl00$m$g_c6ae303a_6013_4adb_8057_63a214bcfd24$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem" value="OK" onclick='if (!PreSaveItem()) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$m$g_c6ae303a_6013_4adb_8057_63a214bcfd24$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem", "", true, "", "", false, true))' id="ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" accesskey="O" class="ms-ButtonHeightWidth" target="_self" type="button"&gt;
  &lt;/td&gt;
</code></pre>

<p>I cannot use ID or name to get the element and check whether it's empty or not.</p>

<p>Thanks in advance.</p>

<p>Edit:</p>

<p>I tried with
if ($("input[title='Start Date']").val().length &lt; 1)
{
alert("test");
}</p>

<p>and it doesn't give me a popup if the field has some data in it but if it's empty it does.
Next step is to add some text after the field (instead of raising an alert) saying "Required Field". How do  I insert this with jQuery/JavaScript after the element I validate?</p>
