1

I have a requirement where if user selects an apex input checkbox then apex command button should be enabled. These two (checkbox,command button) are in columns of page block table.Below is the code snippet.

<apex:pageBlockTable value="{!retrieveList}" var="rpl">
  <apex:column style="width:250px" headerValue="ID" value="{!rpl.pId}"/>
  <apex:column style="width:250px" headerValue="Selected">
      <apex:inputCheckbox id="selectedCheck"/>
  </apex:column>
  <apex:column style="width:250px" headerValue="deduct" value="{!rpl.deduct}"/>
  <apex:column style="width:250px" headerValue="Status" value="{!rpl.Status}"/>
  <apex:column style="width:250px" headerValue="Custom">
    <apex:outputText value="{!IF(rpl.pType == 'Custom','Yes','No')}"/>
  </apex:column> 
  <apex:column style="width:250px" headerValue="">
      <apex:commandButton value="Open Link" disabled="true" />
  </apex:column>
  <apex:column style="width:250px">
    <apex:commandLink value="Customize" />
  </apex:column>
</apex:pageBlockTable>

Strugging a lot. Please suggest a solution. Is it possible to do like this or do we need to change the logic. Please send some sample code.

0

Try this,

<script language="JavaScript">
<!--

function enable_button(status)
{
status=!status; 
    document.f1.other_button.disabled = status;
}
//-->
</script>
</head>
<body onload=enable_button(false);>

<form name=f1 method=post>
<input type="checkbox" name=others onclick="enable_button(this.checked)" >Others
<button type=button name=other_button>
</form>
  • this will not work for me Anurag, thanks for your response. the button and checkboxes are inside a loop (i.e pagablocktable in salesforce) – bhaskar b Jun 23 '16 at 17:25
  • can you post your code ? it will be helpful to know what you are trying to do – Anurag Jun 23 '16 at 17:32
  • <apex:pageBlockTable value="{!retrieveList}" var="rpl"> <apex:column style="width:250px" headerValue="ID" value="{!rpl.pId}"/> <apex:column style="width:250px" headerValue="Selected"> <apex:inputCheckbox id="selectedCheck"/> </apex:column> <apex:column style="width:250px" headerValue=""> <apex:commandButton value="Open Link" disabled="true" /> </apex:column> </apex:pageBlockTable> – bhaskar b Jun 23 '16 at 18:00
0

Here is some sample code that will achieve required functionality:

<Script>
function disableEnableButton(chk){    
   if(chk.checked==true){
    var nearestButton=chk.parentNode.parentNode.getElementsByClassName('btnDisabled')[0];
    nearestButton.disabled='';
    nearestButton.className='btn';
    }
 else{
   var nearestButton=chk.parentNode.parentNode.getElementsByClassName('btn')[0];
   nearestButton.disabled='disabled';
   nearestButton.className='btnDisabled'
  }
 }
</Script>


 <apex:pageBlockTable value="{!retrieveList}" var="rpl">
  <apex:column style="width:250px" headerValue="ID" value="{!rpl.pId}"/>
  <apex:column style="width:250px" headerValue="Selected">
      <apex:inputCheckbox id="selectedCheck" onchange="disableEnableButton(this)"/>
  </apex:column>
  <apex:column style="width:250px" headerValue="deduct" value="{!rpl.deduct}"/>
  <apex:column style="width:250px" headerValue="Status" value="{!rpl.Status}"/>
  <apex:column style="width:250px" headerValue="Custom">
    <apex:outputText value="{!IF(rpl.pType == 'Custom','Yes','No')}"/>
  </apex:column> 
  <apex:column style="width:250px" headerValue="">
      <apex:commandButton value="Open Link" disabled="true" />
  </apex:column>
  <apex:column style="width:250px">
    <apex:commandLink value="Customize" />
  </apex:column>
</apex:pageBlockTable>

Here is more explaination for your understanding:

  • whenever a checkbox is clicked go to its parent row <TR> tag.
  • Find first button in the row.
  • Based on checkbox value enable disable button.
  • Thanks Mukesh for your response, it is working perfectly. Could you please give me some code to disable the buttons on page load. At the time of page load all the buttons should be disabled. – bhaskar b Jun 28 '16 at 4:22

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.