0

I have a page where in I have two tables. I need to make the tables appear and disappear on button click. I tried to achieve through jquery. But both tables always appear on button click. However on page load only one table appears. My code is below:

<apex:page standardcontroller="Adpub__c" extensions="PageBlockTableFieldSetExample" id="page"> 

  <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>

  <script type="text/javascript">
    J$ = jQuery.noConflict();
    J$(document).ready(function(){
      alert(J$);
      J$('[id$=pbt2]').hide();

    });


  function enableEdit(){
         J$('[id$=pbt]').show();
         J$('[id$=pbt2]').hide();
    }
    function enableSave(){
         J$('[id$=pbt]').hide();
         J$('[id$=pbt2]').show();
    } 
  </script>  



  <apex:form id="frm">
    <apex:pageblock id="pbId">   

        <apex:pageblocktable value="{!adpubs}" var="pbsIs" id="pbt">

          <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}" id="rep">
            <apex:column headerValue="{!f.label}" id="col">
                <apex:inputField value="{!pbsIs[f]}" id="ipf"/> 
              </apex:column>
          </apex:repeat>  
        </apex:pageblocktable>

        <apex:pageblocktable value="{!adpubs}" var="pbsIs" id="pbt2">  
          <apex:repeat var="f2" value="{!$ObjectType.Adpub__c.FieldSets.SystemFieldSet}" id="rep2">
            <apex:column headerValue="{!f2.label}" id="col2">
                <apex:inputField value="{!pbsIs[f2]}" id="ipf2"/> 
              </apex:column>
          </apex:repeat>  

       </apex:pageblocktable>

        <apex:commandButton Value="Edit" onclick="enableEdit();" rerender="pbId" id="eb"/>
        <apex:commandButton Value="Save" onclick="enableSave();" rerender="pbId" id="sb"/>
      </apex:pageblock> 
</apex:form>  
</apex:page>
1

Just added "return false;" after the function call to the onclick event in button. It worked!

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.