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

how to disable commandbutton from js

I'm trying to disable a commandbutton when any element of a form has been changed.

My js for detecting the form change is working ok, but the following js does not succeed in enablng or disabling the button.


<script type="text/javascript">

    function enableCreateButton(state) {
        document.getElementById('{!$Component.thePage.theForm.thePageBlock.thePageBlockButtons.theCreateButton}').disabled = state;

Here's the markup:

<apex:commandButton value="Create Lead" 


 I can run enableCreateButton(true) or enableCreateButton(false) in the firebug console, and it has no effect. I can display document.getElementById('{!$Component.thePage.theForm.thePageBlock.thePageBlockButtons.theCreateButton}') in the console, and I see the component. I can see that running enableCreateButton changes the value of its disabled element.


What am I doing wrong here?






For one thing, I need to dynamically modify the class:


        function disableCreateButton(q) {
            theCreateButton.disabled = q;
            theCreateButton.className = q ? 'btnDisabled' : 'btn';