The function “getTagFromIdentifierAndTitle” is used by SharePoint particularly for changing form fields. But it is good enough only if you have straight forward fields. If you have enabled “Fill-in” values, it will not be able to find the correct element. Here is a extended version of this function to get the “Fill-in” enabled field.
function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
var len = identifier.length, colonindex, splittitle, taglen, titlelen = title.length, slen;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
taglen = tags[i].title.length;
if(taglen<titlelen)
continue;
splittitle = tags[i].title.replace(title,"");
slen = splittitle.length;
if(slen == taglen || (slen > 0 && splittitle.indexOf(":") == -1))
continue;
if ((identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
{
return tags[i];
}
}
return null;
}
Leave a Reply