You need to sign in to do that
Don't have an account?
Mahu Sims
Can the function occur before the button click?
Hi!
I am creating a custom detail page button that needs to change color based on the data from our custom field. This is an onClick js button.
The problem I am having is that the button does not change color until after the button is clicked, while i want this to occur as soon as the page is loaded.
Here is what I have so far:
Thanks in advance for your help!
I am creating a custom detail page button that needs to change color based on the data from our custom field. This is an onClick js button.
The problem I am having is that the button does not change color until after the button is clicked, while i want this to occur as soon as the page is loaded.
Here is what I have so far:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} var growth = '{!Contact.Orders_Growth_YOY_Change_User__c}'; (function() { if(growth == ''){ var button = document.getElementsByName('check_contact_health')[0]; button.style.background = 'url("http://www.dcfanboy.com/media/catalog/product/cache/1/image/265x265/17f82f742ffe127f42dca9de82fb58b1/s/m/smoke_gray.jpg)'; }()); alert("This contact has not begin to bill with Mimeo yet. There will be no growth data until contact has billed for at least 12 months"); } else if(growth >=1){ (function() { var button = document.getElementsByName('check_contact_health')[0]; button.style.background = 'url("http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG")'; }()); alert("This contact's orders are currently growing. This contact's year over year order growth is equal to '{!Contact.Orders_Growth_YOY_Change_User__c}'"); } else if(growth ==0){ (function() { var button = document.getElementsByName('check_contact_health')[0]; button.style.background = 'url("http://upload.wikimedia.org/wikipedia/commons/d/d0/Color-yellow.JPG")'; }()); alert("This contact's orders are currently the same as they were in the previous 12 months. This contact's year over year order growth is equal to '{!Contact.Orders_Growth_YOY_Change_User__c}'"); } else{ (function() { var button = document.getElementsByName('check_contact_health')[0]; button.style.background = 'url("http://www.colorcombos.com/images/colors/FF0000.png")'; }()); alert("This contact is currently at risk as the contact is ordering less than they did in the previous 12 months. This contact's year over year order growth is equal to '{!Contact.Orders_Growth_YOY_Change_User__c}'"); }
Thanks in advance for your help!
var growth = '{!Contact.Orders_Growth_YOY_Change_User__c}';
look like when the page is rendered? If you are starting out with an empty contact then this will be a blank string.