Home > Javascript, SharePoint > Extended Function getTagFromIdentifierAndTitle to get Fill-In enabled Dropdown

Extended Function getTagFromIdentifierAndTitle to get Fill-In enabled Dropdown

January 26th, 2010 Leave a comment Go to comments

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;
}
Categories: Javascript, SharePoint Tags:
  1. No comments yet.
  1. No trackbacks yet.