1

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);        
    }
  • How is it not working? Do both buttons display? – Antonio Manente Dec 28 '15 at 13:26
  • when hasuser is false register and accept gets displayed. When hasuuser is true none of the buttons gets displayed @AntonioManente – Rimii Dec 29 '15 at 4:42
4

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

rendered="{!!hasuser}"
  • I have tried it too...its not working either @himanshu – Rimii Dec 28 '15 at 12:58
  • when you make that false? because on page load it can be either true or false – Himanshu Dec 28 '15 at 13:01
  • I use this syntax: {!hasuser = false} – Jason Dec 28 '15 at 13:39
  • 1
    what is the data type of hasUser ? – Himanshu Dec 28 '15 at 13:45
  • 1
    @Rimii, I agree with Himanshu, alternate syntax is rendered="{!NOT(hasUser)}" but this shouldn't matter; is the visibility part of an Ajax refresh? – cropredy Dec 28 '15 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.