Knowledge.ToString()

Extended Function getTagFromIdentifierAndTitle to get Fill-In enabled Dropdown

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;
}

Share

Comments

Leave a Reply

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