Replace a field to a button or Create a button on Form, and attach the onclick() event

This is an example on how to create a button on the form, using java script. First of all we need to create a nvarchar attribute and put it on the form where we want our button.
In this example my attribute’s schema name is new_test.

Here is the code


someFunction = function()


alert(“button clicked!”);


// This is how we call the button, what we see

crmForm.all.new_test.DataValue = “Button”;

// We could align it a bit = “center”;

crmForm.all.new_test.vAlign = “middle”;

//we make the mouse look as a hand when we’re moving over = “hand”; = “#CADFFC”; = “#FF0000”; = “#330066”; = “bold”;

crmForm.all.new_test.contentEditable = false;

//we attach some events in order to make it look nice 🙂





function color3() { = “#6699FF”;


function color4() { = “CADFFC”;


function color1() { = “000099”;


function color2() { = “FF0000”;


//here we attach what we want our button do

Replace a field to a label (use replaceNode())
/* replace new_field_d to a label */
if (crmForm.all.new_field != null)
var html = document.createElement( “”);
html.innerText = “this is a lable”;

Append text under a field (you don’t need to create an attribute for that)
/* append text under new_field */
if(crmForm.all.new_field != null)
var html= document.createElement( “”);
html.innerText = “this is a text field”;

%d bloggers like this: