I have some javascript that runs when the new item form is opened. The code works fine in SharePoint 2010, but will not work in SharePoint 2013. When the form loads, I get an Unable to set property 'value' of undefined or null reference error so the getTageFromIdentifierandTitle function is returning null, but I can't figure out why.
I am using the below code.
_spBodyOnLoadFunctionNames.push("executeOnLoad");
function executeOnLoad()
{
getTagFromIdentifierAndTitle("input","","RequestID").value = id;
getTagFromIdentifierAndTitle("input","","Date Created").value = simpleDate;
}
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;
}