I have a formula field on Lead (Profile__c) which gets updated with different values depending on the another field (Weight__c) given. Below is the formula:
IF (AND(Weight__c> 0, Weight__c <= 17), "A",
IF (AND(Weight__c>= 18, Weight__c <= 32), "B",
IF (Weight__c>= 32, "C", "")))
Now I have a button on Lead which displays 3 different images depending on Profile field's value. I am achieving this with Java script. Everything is working fine except for whenever the value of Profile__c is C, its displaying the image related to option B and not the image related to option C of Profile. In addition to this, if the Profile__c field is blank and I click on the button, its still displaying the image related to option B which shouldn't be happening. Kindly help.
If possible, kindly help me with a VF sample code to replace the same functionality which is happening through Javascript. Thanks in advance.
Here is the Java script
<apex:page standardController="Lead">
<apex:form >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var result=getParameterByName('lId');
var url;
if(result=='A')
{
url='https://ap1.salesforce.com/resource/1410344346000/A';
}
else if(result='B')
{
url='https://ap1.salesforce.com/resource/1410344193000/B';
}
else if(result='C')
{
url='https://ap1.salesforce.com/resource/1413133715000/C';
}
window.location.href=url;
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
});
</script>
</apex:form>
</apex:page>