CRM 2011 JS: Dynamic Controls in CRM Form (Button) 1

// Add button in crm

function addButton(attributename) {

    if (document.getElementById(attributename) != null) {

        var sFieldID = "field" + attributename;

        var elementID = document.getElementById(attributename + "_d");

        var div = document.createElement("div");

        div.style.width = "19%";

        div.style.textAlign = "right";

        div.style.display = "inline";

        elementID.appendChild(div, elementID);

        div.innerHTML = '<button id="' + sFieldID + '"  type="button" style="margin-left: 4px; width: 100%;" ><img src="/_imgs/img.gif" border="0" alt="Dial this number"/></button>';

        document.getElementById(attributename).style.width = "80%";

        document.getElementById(sFieldID).onclick = function () {onbuttonclick(); };

    }

}

 

function onbuttonclick() {

    alert('Hi');

}