Home > CRM 4.0, Customizations, JavaScript > Add a Button to a Form

Add a Button to a Form

This post is to show how to add a Button to a MS CRM Form, not to the Navigation Pane nor to the Menu Bar, but to the actual Form itself.
In this post I will show a simple usage of the Button, to show its function. You can understand that more advanced functions can be triggered by the button, but that’s not the aim of this post.For this example I have used the default Contact Form. The Address Section is hidden onLoad and a Button is shown.

Button on Form

By Clicking on the Button the Section with the Address Details is shown again. In this example the Button Disappears, because it has no use anymore. (I could have added a function to hide the section again).

Button on Form2

To achieve the above I have created a new Section with a new Attribute (new_button).

Button on Form3

Next to that I placed the following Script in the onLoad of the Form:

Update: 9th March 2010 - updated code blocks - wordpress broke the code!

// Start of onLoad Code

//to hide the address details onload
crmForm.all.address1_name_c.parentElement.parentElement.parentElement.style.display = 'none';

// Replace the attribute new_button with the button and create a link to the onclick function
function CreateButton() {
var fieldTable = crmForm.all.new_button_d;
var html = "<table border='0' cellspacing='0' cellpadding='0'><tr><td width='0px'>" + fieldTable.innerHTML + "</td><td width='200px'><input type='button' value='Show Address Details' onclick='Button_OnClick()' style='background-color:#d8e8ff' style ='border-width:2px'/></td></tr></table>";
fieldTable.innerHTML = html;
//hide the new_button attribute
document.all.new_button.style.display='none';
crmForm.all.new_button_c.innerText="";
}
// Function to be triggered onClick
Button_OnClick = function() {
//to show the address details
crmForm.all.address1_name_c.parentElement.parentElement.parentElement.style.display ='block';
//In this case I hide the button, because I haven't added the button has not function anymore in this case
crmForm.all.new_button_c.parentElement.parentElement.parentElement.style.display ='none';
}
// Initialization: Execute the selected sample
CreateButton();

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , , ,

  1. viral kothari
    September 14th, 2009 at 15:20 | #1

    Sir,

    Code given here is not working.

    -viral

  2. March 9th, 2010 at 12:05 | #2

    Hi Viral,

    I have updated the code block. should work now. apologies for this.

    -Ibrahim

  1. No trackbacks yet.