jQuery/JavaScript validation controls -


I have a form on a SharePoint site and want to get some field field (datetime picker etc.). Add some other areas appear / to hide and use a post-red * Required fields Title I (for example):

  // Strategic Priority $ ( 'Nobr: include ( "Strategic Priority "). ') .closest (' tr ') show (); . $: HTML (; Verify \ "& gt; the * & lt; / span & gt;" include "span class = \ strategic priority & lt") ( 'nobr ( "strategic priority")); // Measure performance $ ('Nommer:' includes ("display measurement") '). Closest ('tr'). Hide (); // Start Date $ ('Normal: In ("Start Date")' '). Closest ('tr'). Show (); $ ('Normal:' ("Start Date")). Html ("Start Date & lt; span class = \" Validate \ "& gt; * & lt; / span & gt;");  

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

HTML looks like this:

  & 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_strdatetimekantrolids [ "Spduidte"] = "Ktl00_m_g_k6ae303a_60l3_4adb_8057_63a2l4bcfd24_ktl04_ktl00_ktl00_dattimefield_dattimefielddte"; & Lt; / Script & gt; & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; Td square = "ms-dtinput" & gt; & Lt; For = "Ctl00_m_g_c6ae303a_60l3_4adb_8057_63a2l4bcfd24_ctl04_ctl00_ctl00_DateTimeField_DateTimeFieldDate" style = Labels "display: none;" & Gt; Target date date & lt; / Labels & 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> HTML for button  

generated:

  & 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 = "right" onclick = 'if (! returned PreSaveItem ()); WebForm_DoPostBackWithOptions (new WebForm_PostBackOptions ( "ctl00 really $ m $ g_c6ae303a_6013_4adb_8057_63a214bcfd24 $ ctl00 $ toolBarTbl $ RightRptControls $ ctl00 $ ctl00 $ diidIOSaveItem", "",, "", "", 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;  

I can not use the ID or name to get the element and can check whether it is empty or not.

Thanks in advance.

Edit:

I have tried ($ ("Input [title = 'start date']"). Val (). Length <1) {Warning ("testing"); }

And it does not give me a popup if it has some data in the field, but if it is empty then the next step is to add some text after the field (instead of raising a warning) Saying "Required field" How do I insert this element with jQuery / JavaScript after I validate?

How about something like this? Each (function (var obj = $ (this); if (obj.val (). Length & lt; if not already notified 1) {// check, if} {obj.after ('Required field') text (obj.data ('notified'!); Obj.data ('notified', true);}}});


Comments