Saturday, September 08, 2012

JSF Tip of the Day: JavaScript Execute a Button Once

I saw this question on a NetBeans forum from a new developer.

"How do you disable a button on a page after one click?"
I figured since I was going to answer the question anyway, I would publish a quick example of one way to do it.
1
2
3
4
5
6
7
<script type="text/javascript">
    function once() {
        alert('Hello');
        document.getElementById('form4:button1').onclick = null;
        document.getElementById('form4:button1').value = 'All Done';  
    }
</script>
1
2
3
<h:form id="form4">
        <h:button id="button1" onclick="once();return false;" value="Run Once!"/>
</h:form>

0 comments :

Popular Posts