I'm working on an inline visualforce page that is embedded into a standard lead detail record. I'm using javascript logic on the vf page to get the value of a field and then, depending on the value retrieved, display different messages. The issue I'm a having is that I'm not able to test in the javascript whether the field is null/blank/''/"".
My code looks like:
<div id="divFDNC"></div>
<script language="javascript">
if(document.getElementById('divFDNC')){
var gIE = document.all ? true:false;
if({!Lead.Checkbox__c} == true){
if({!Lead.Custom_Status__c} == '00' || {!Lead.Custom_Status__c} == ''){
document.getElementById('divFDNC').innerHTML = '<font style="font-size: 11px;" class="FDNC_Message"> <b>MY MESSAGE</b></font>'
}
else{
document.getElementById('divFDNC').innerHTML = '<font style="font-size: 11px;" class="FDNC_Message"> <b>MY MESSAGE 2</b></font>'
}
The message works when I enter '00' into the Custom_Status__c field. However, when the Custom_Status__c field is blank, then it doesn't display the message like it should. I've tried the following to get it to work (no luck on any of them):
'{!Lead.Custom_Status__c}' == '' / null / NaN / undefined
"{!Lead.Custom_Status__c}" == "" / null / NaN / undefined
{!Lead.Custom_Status__c} == '' / null / NaN / undefined
Does anyone know how to properly test that a field is blank, using javascript? Thanks in advance for any help you can provide.
==
. Reserve that for Apex. Just test against""
for an empty string. – crmprogdev Sep 2 '15 at 17:57'{!Load.Custom_Status__c}'
should have worked as it works for me. Alternatively you can change it toif{!(ISBLANK(Lead.Custom_Status__c)}
without any quotes. – Aayush K Sep 2 '15 at 18:10if ({!ISBLANK(...)})
with parentheses. – Adrian Larson♦ Sep 2 '15 at 18:12