Hey hi guys if you are looking out for javascript validation for MOSS2007 & SharePoint 2010 then here is some Javascript
//this function is used to find control in page
//Tagname :- is nothing but tages in html like "INPUT","DIV"
//Identifer:- Control in sharepoint i.e DateTimeFieldDate control
//Title :- for example if we create field with "Contract Date" then out title could be "Contract Date"
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) { var tempString = tags[i].id; if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) { return tags[i]; } } return null; }
//past this function in our page using sharepoint designer thats its ready to go
function PreSaveAction() { var date1 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Contract Date"); var date2 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Contract End Date"); var arrDate1 = date1.value.split("/"); var useDate1 = new Date(arrDate1[2], arrDate1[1]-1, arrDate1[0]); var arrDate2 = date2.value.split("/"); var useDate2 = new Date(arrDate2[2], arrDate2[1]-1, arrDate2[0]); if(useDate1 > useDate2)
{
alert("The end date cannot happen earlier than the start date");
return false; // Cancel the item save process
}
return true; // OK to proceed with the save item
}
other examples are :-
//for DropDown user following parameter
var country = getTagFromIdentifierAndTitle("select", "dropDownList", "Country");
//for TextField(Text box) user following parameter
var title = getTagFromIdentifierAndTitle("input", "TextField", "Requested Title");
//for MultipleLine-TextField user following parameter
var description = getTagFromIdentifierAndTitle("textarea", "TextField", "Description of the change");
No comments:
Post a Comment