1

I am trying to write a javascript button that only redirects the user if the field Data_Confirmed__c = TRUE, it it is FALSE then they should receive an alert to confirm their data first. I am not getting any errors but it even though the field is FALSE it is still redirecting the user when it shouldn't.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

if({!Onsite_Review__c.Data_Confirmed__c}=="FALSE") {
alert("Please confirm the data.");
}
else{
window.open('/apex/loop__looplus?sessionId={!$Api.Session_ID}&eid={!Onsite_Review__c.Id}&contactId={!Onsite_Review__c.FSC_ContactId__c}&header=false&sidebar=false&hidecontact=true&tabclass=Custom51Tab&autorun=true&attach=false&ddpIds=a0Fa000000M3fOH');
}

Alternatively if I try to do the opposite and check if the field is != to "TRUE" then it always alerts and never opens the window when it should.

    {!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

if({!Onsite_Review__c.Data_Confirmed__c}!="TRUE") {
alert("Please confirm the data.");
}
else{
window.open('/apex/loop__looplus?sessionId={!$Api.Session_ID}&eid={!Onsite_Review__c.Id}&contactId={!Onsite_Review__c.FSC_ContactId__c}&header=false&sidebar=false&hidecontact=true&tabclass=Custom51Tab&autorun=true&attach=false&ddpIds=a0Fa000000M3fOH');
}
0

1 Answer 1

2

Use your browser's inspect element feature (see e.g. How do I start to debug my own Visualforce/JavaScript?) to see what text the Visualforce has generated. That will probably be:

if(false=="FALSE") {

or

if(true=="FALSE") {

neither of which are true (as JavaScript expressions).

So instead you need something like (as JavaScript is case sensitive too):

if("{!Onsite_Review__c.Data_Confirmed__c}"=="false") {

or better:

if(!{!Onsite_Review__c.Data_Confirmed__c}) {

Note that this code is appropriate if the page does not allow the field to be changed; if it did allow the field to be changed you would need to look at the current value of the input field.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .