You need to sign in to do that
Don't have an account?

Error Message
I am trying to display an Error Message when the user does not check a checkbox when the user clicks on the Save command button. However, my message component doesnt tie in to the command button. When i click on save, the page proceeds to the next one, without displaying the error message.
I used get, set to get the value of the checkbox in the Controller
Code:
public void setagreeCheckBox(Boolean checkBox) { this.checkBox = checkBox; } public Boolean getagreeCheckBox() { return this.checkBox; }
I have defined a function to check the value of the checkbox and add the message to message component.
Code:
<apex:page controller="NewEmployeeRequest2" sidebar="true" showHeader="true" > <head> <script language="Javascript"> function check(boolean checkboxvalue) { var returnvalue= true; if(checkbox=='false') { returnvalue=false; alert(checkbox); ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Please check and agree to proceed')); } return returnvalue; } </script> </head> <apex:form id="NewEmployeeRequest2"> <apex:pageBlock > <apex:inputfield value="{!case.Rules_of_Behavior_Agree__c}" /> <apex:commandButton action="{!Cancel}" value="Cancel" /> <apex:commandButton action="{!Save}" value="Continue" onclick="return check('{!agreeCheckBox}')"> <apex:actionSupport event="onclick" rerender="ErrorMessage"/> </apex:commandButton> <apex:pageMessage id="ErrorMessage" rendered="return check('{!agreeCheckBox}')" severity="warning" strength="2"> </apex:pageMessage> </apex:pageBlock> </apex:form> </apex:page>
This doesnt work. In addition, I have multiple fields in my form which I have to validate.
Thank you in advance,
Anchal
You need to override the onsubmit method of the form to validate your checkboxes.
The javascript for the onsubmit handler