Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am facing a problem while disabling the command button after one click. I am using action function for this but it's not working well don't know why?? can anybody please help me to correct 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();"  /> 

1 Answer

0 votes
by (32.1k points)

It seems like you're not setting the disabled attribute on the Command Button. Use this.disabled=true; or this.disabled="disabled";.

Try this:

<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>

Browse Categories

...