Disable command button after one click

I am facing an issue when disabling the command button after one click. I am using action function for this, but it does not work well, not sure why? can any body please help me fix my code if i am wrong?

  <script>
     function validationRule(){
     savePost();
     }
  </script>

      

vf code:

<apex:actionStatus startText="Loading..." stopText="" id="str"> </apex:actionStatus>
               <apex:actionRegion >
                        <apex:actionFunction name="savePost" action="{!save}" rerender="" status="str" >
                       </apex:actionFunction>
              </apex:actionRegion>
<apex:commandButton image="{!URLFOR($Resource.Test, 'Post_Button.png')}" value="Post"  onclick="validationRule();"  /> 

      

Please correct me ..

+3


source to share


1 answer


It looks like you are not setting the disabled attribute on the Command Button. Use this.disabled=true;

or this.disabled="disabled";

.

Try the following:



<apex:page standardcontroller="Account">
    <apex:form >
        <script type="text/javascript">
            function validate() {
                // validate code here
                savePost();
            }
        </script>
        <apex:actionfunction name="savePost" action="{!save}" rerender="" status="str" />
        <apex:commandbutton value="Save New Account Value" onclick="this.disabled='disabled'; validate();" />
        <apex:actionstatus startText="Loading..." stopText="" id="str" />
    </apex:form>
</apex:page>

      

+6


source







All Articles