Extended Function getTagFromIdentifierAndTitle to get Fill-In enabled Dropdown

By | January 26, 2010

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;
}
Vishal Monpara is a full stack Solution Developer/Architect with 12 years of experience primarily using Microsoft stack. He is currently working in Retail industry and moving 1’s and 0’s from geographically dispersed hard disks to geographically dispersed user’s mind leveraging geographically dispersed team members.

Leave a Reply

Your email address will not be published. Required fields are marked *