function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hgolovhgolov 

Disable Submit Button to prevent Multiple form submission

Hi, and thank you for taking the time to look at my question.

I have a standard set of js functions that I use for form validation. One of the features I added was to disable the submit button before submitting the form to prevent a multiple submission. This is especially useful when submitting financial transactions, but in general it comes in handy.

HOWEVER when I try to implement this in my vf page, it makes the page reload, instead of redirecting to the correct page.

Does anyone have any idea why?

Here is a code snippet that I tried in my onSubmit function:

 

 <!-- submit button
-->
<apex:commandButton id="submitArea" value="Sign Me Up!" action="{!save}"/>

<script type='text/javascript'>
document.getElementById('{!$Component.submitArea').disabled = true;
myApp = navigator.appVersion
if(myApp.indexOf('America Online Browser') == -1){
if(checkForm())
return true;
document.getElementById('!$Component.submitArea').disabled = false;
return false;
}
return true;
</script>

 

 


 

 

Bhawani SharmaBhawani Sharma

Can you please try this :

 

<apex:commandButton id="submitArea" value="Sign Me Up!"  action="{!save}" onClick="this.disabled=true;"/>
hgolovhgolov

Thanks for taking the time to answer.

When I do that it prevents form submission, and DOES NOT disable the button! It does go to the onsubmit function, and then when it's finished it just stops.

Any ideas?

bob_buzzardbob_buzzard

I had the same thing using chrome as the browser - disabling via onclick worked for firefox and IE.

 

I've ended up using something similar to the following:

 

 

<apex:commandButton id="submitArea" value="Sign Me Up!"  action="{!save}" onClick="this.onFocus=this.blur();"/>

It doesn't actually disable the button, but stops the user clicking on it.