Wednesday, August 3, 2011

Get Sharepoint Control ID using Javascript in Sharepoint 2010



<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">





//find a controlid like textbox or dropdownlist
function getControlID(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 (tempString.match(title)) {

                    return tags[i].id;
                }

            }
            return null;
        }



function Caller()
{
//you can call like this

  var dropdownid = getControlID("select""Choice""Content Type");
}

  _spBodyOnLoadFunctionNames.push("Caller");


</asp:Content>



No comments:

Post a Comment

Followers

Blog Archive