VwpFAQButtondisable

How can I disable a button after a user clicks on it?

Sometimes, after an end user submits a form, it takes awhile for the response. In the meantime, you don't want the end user to keep clicking the submit button. The trick is to disable the button from the client side. However, you don't want to disable the button until the client has submitted the form. The solution is to use the setTimeout function to delay disabling the button until after the form is sent to the server.

First you add JavaScript LIKE the following to the page's JSP file (you have to replace button1 with whatever the id is for your button). I add it just before the </ui:head> tag.


<script type="text/javascript"><![CDATA[                                          
function disableButton() {
var domNode = document.getElementById('form1:button1')
domNode.setProps({disabled: true});
}]]></script>


Next, in the Visual Designer, select the button and, in the Properties window, set the onClick property to the following:

setTimeout('disableButton()', 1)

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo