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
TylerBrooksTylerBrooks 

How to get submit button to be enabled after checkbox is checked on page?

I have some code for a page and I have it to where the submit button is greyed out if a checkbox is unchecked. However whenever you check the box it doesn't enable the submit button like i'm wanting. 

Here is my code 
<apex:page standardController="RMA__c">
    <apex:form >
        <apex:outputPanel id="thePanel" rendered="{!(RMA__c.RLI_has_QUOTE_SO__c == true)}">
        <apex:pageBlock title="Confirm Information" mode="edit">
            <apex:pageBlockSection title="Confirm the  new field values" columns="2" rendered="{!(RMA__c.Show_the_box__c == true)}">
                <apex:outputfield value="{!RMA__c.Contact__c}"/>
                <apex:outputfield value="{!RMA__c.Shipping_Priority__c}"/>
                <apex:outputfield value="{!RMA__c.Ship_to_Address__c}"/>
                <apex:outputfield value="{!RMA__c.Bill_to_Address__c}"/>
                <apex:inputfield value="{!RMA__c.Request_Priority__c}"/>
                <apex:inputField value="{!RMA__c.Changes_are_reviewed__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Submit" disabled="false" rendered="{!(RMA__c.Changes_are_reviewed__c == true)}"/>
                <apex:commandButton action="{!save}" value="Submit" disabled="true" rendered="{!(RMA__c.Changes_are_reviewed__c != true)}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

And here is the page:

User-added image​​​​​​​
Best Answer chosen by TylerBrooks
TylerBrooksTylerBrooks
So I figured out the answer to my question and the reason it wasn't working before, for others who are having this issue here is my code:
 
<apex:page standardController="RMA__c">
    <apex:form >
        <apex:outputPanel id="thePanel" rendered="{!(RMA__c.RLI_has_QUOTE_SO__c == true)}">
        <apex:pageBlock id="TheBlock" title="Confirm Information" mode="edit">
            <apex:pageBlockSection id="theSection" title="Confirm the  new field values" columns="2" rendered="{!(RMA__c.Show_the_box__c == true)}">
                <apex:outputfield value="{!RMA__c.Contact__c}"/>
                <apex:inputfield value="{!RMA__c.Shipping_Method__c}"/>
                <apex:outputfield value="{!RMA__c.Ship_to_Address__c}"/>
                <apex:outputfield value="{!RMA__c.Bill_to_Address__c}"/>
                <apex:inputfield value="{!RMA__c.Request_Priority__c}"/>
                <apex:inputfield value="{!RMA__c.Specific_Asset_Requested__c}"/>
                <apex:inputField value="{!RMA__c.Changes_are_reviewed__c}" id="reviewed">
                    <apex:actionSupport event="onchange" rerender="thePanel"/> 
                </apex:inputField>
            </apex:pageBlockSection>
            <apex:pageblockButtons id="button">
            <apex:commandButton value="Submit" action="{!save}" id="saveit" disabled="{!IF(RMA__c.Changes_are_reviewed__c!=true,true,false)}"/>
            </apex:pageblockButtons>
       </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

The reason it wasn't work was because I was adding the onchange to the same line as the input field value for the checkbox, not doing the action Support in a seperate line like shown in my correct code.

Hope this helps others!

-Tyler

All Answers

TylerBrooksTylerBrooks
That image is awful so here's a link to the screenshot of it: http://prntscr.com/lu288c
sindhura (Heptarc)sindhura (Heptarc)
 Hello Tyler Brooks,
VF:
<input type="checkbox" id="checkme"/> <input type="submit" name="sendNewSms" class="inputButton" disabled="disabled" id="sendNewSms" value=" Send " />
Java Script:
var checker = document.getElementById('checkme');
var sendbtn = document.getElementById('sendNewSms');
 // when unchecked or checked,run the function
checker.onchange = function(){
 if(this.checked){
sendbtn.disabled = false;
 } else {
sendbtn.disabled = true;
 }
 }
Try this piece of code.
Hope this will help you.
Thank you.
TylerBrooksTylerBrooks
@Sindhura,

So I added the code in but when I try to hit the submit it doesn't save the record or do anything, the primary function I'm hoping for it to do is check a checkbox but when I do an onclick it doesn't check the checkbox.

Here is the code
<apex:page standardController="RMA__c">
    <apex:form >
        <apex:outputPanel id="thePanel" rendered="{!(RMA__c.RLI_has_QUOTE_SO__c == true)}">
        <apex:pageBlock title="Confirm Information" mode="edit">
            <apex:pageBlockSection title="Confirm the  new field values" columns="2" rendered="{!(RMA__c.Show_the_box__c == true)}">
                <apex:outputfield value="{!RMA__c.Contact__c}"/>
                <apex:outputfield value="{!RMA__c.Shipping_Priority__c}"/>
                <apex:outputfield value="{!RMA__c.Ship_to_Address__c}"/>
                <apex:outputfield value="{!RMA__c.Bill_to_Address__c}"/>
                <apex:inputfield value="{!RMA__c.Request_Priority__c}"/>
                <apex:inputField value="{!RMA__c.Changes_are_reviewed__c}"/> //Do not need this to be viewable now, just need it to be checked when submit button is pressed.
            </apex:pageBlockSection>
            Changes have been reviewed <input type="checkbox" id="checkme"/> <input type="submit" name="sendNewSms" class="inputButton" disabled="disabled" id="sendNewSms" value="Submit" onClick="(!(RMA__c.Changes_are_reviewed__c == true)}"/>
            <script>
            var checker = document.getElementById('checkme');
            var sendbtn = document.getElementById('sendNewSms');
            checker.onchange = function()
            {
             if(this.checked)
             {
                sendbtn.disabled = false;
             } 
             else 
             {
                sendbtn.disabled = true;
             }
            }
            </script>
       </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

 
TylerBrooksTylerBrooks
Follow up to Above, so I got it to where if the button I wanted pressed (Changes_are_reviewed__c) is checked it will change the enable/disable of an input button but I need it to be an apex command button to update the field values with updated information, so Is there a way to either, enable/disable an apex command button, or how do I get the input button to update the record.
 
TylerBrooksTylerBrooks
So I figured out the answer to my question and the reason it wasn't working before, for others who are having this issue here is my code:
 
<apex:page standardController="RMA__c">
    <apex:form >
        <apex:outputPanel id="thePanel" rendered="{!(RMA__c.RLI_has_QUOTE_SO__c == true)}">
        <apex:pageBlock id="TheBlock" title="Confirm Information" mode="edit">
            <apex:pageBlockSection id="theSection" title="Confirm the  new field values" columns="2" rendered="{!(RMA__c.Show_the_box__c == true)}">
                <apex:outputfield value="{!RMA__c.Contact__c}"/>
                <apex:inputfield value="{!RMA__c.Shipping_Method__c}"/>
                <apex:outputfield value="{!RMA__c.Ship_to_Address__c}"/>
                <apex:outputfield value="{!RMA__c.Bill_to_Address__c}"/>
                <apex:inputfield value="{!RMA__c.Request_Priority__c}"/>
                <apex:inputfield value="{!RMA__c.Specific_Asset_Requested__c}"/>
                <apex:inputField value="{!RMA__c.Changes_are_reviewed__c}" id="reviewed">
                    <apex:actionSupport event="onchange" rerender="thePanel"/> 
                </apex:inputField>
            </apex:pageBlockSection>
            <apex:pageblockButtons id="button">
            <apex:commandButton value="Submit" action="{!save}" id="saveit" disabled="{!IF(RMA__c.Changes_are_reviewed__c!=true,true,false)}"/>
            </apex:pageblockButtons>
       </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>

The reason it wasn't work was because I was adding the onchange to the same line as the input field value for the checkbox, not doing the action Support in a seperate line like shown in my correct code.

Hope this helps others!

-Tyler
This was selected as the best answer