[SalesForce] Button Render depending on a boolean value

I have the following piece of code

function toggleButton(box, id1, id2) {
var elm1 = document.getElementById(id1);
var elm2 = document.getElementById(id2);
if(box.checked){
elm1.style.display = "";
elm2.style.display = "";
} else {
elm1.style.display = "none";
elm2.style.display = "none";
}
}
<td width="10%"/>
<td width="80%"><input type="checkbox" name="checkbox-mini-0" id="checkbox-mini-0" data-mini="true" onclick="javascript: toggleButton(this,'j_id0:LandingForm:inviteRegisterButton','j_id0:LandingForm:inviteLoginButton');"></input>&nbsp;<b>Yes, I have read the provisions document and agree with the conditions</b></td>
<td></td>
<apex:commandButton id="inviteRegisterButton" value="Register and Accept" style="display:none;width:125px;height:25px;font-weight:bold;font-size:12px;background-color:#f9f9f9;border-radius:6px;" 
   action="{!AppPA}" rendered="!{!hasuser}"/>
&nbsp;&nbsp;
<apex:commandButton id="inviteLoginButton" value="Login and Accept" style="display:none;width:125px;height:25px;font-weight:bold;font-size:12px;background-color:#f9f9f9;border-radius:6px;" 
   action="{!AppPB}" rendered="{!hasuser}"/>
&nbsp;&nbsp;

hasuser is a variable of the controller.

Here one of the two buttons gets displayed depending on whether the value of hasuser is true or false.

  1. If hasuser is true Register and Accept gets displayed

  2. If hasuser is false Login and Accept gets diplayed. This code doesn't seem to be working. can anyone tell me where am I going wrong?

This where the value of hasuser is being set to true or false. This is the constructor of the controller class

public LandingPageController(){

UserId= ApexPages.currentpage().getParameters().get('UserId');
hasuser=false;
        System.debug('hasusercheck 1 '+hasuser);
        if(UserId!=null){
            hasuser=true;
            System.debug('hasusercheck 2 '+hasuser);
         }
        System.debug('hasusercheck 3 '+hasuser);        
    }

Best Answer

Your first condition is wrong if you are doing NOT in your condition correct syntax is

rendered="{!!hasuser}"
Related Topic