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
mac adminmac admin 

Check box filed as mandetory in custom vfpage

Hi all,
I want to make the check box as mandetory before saving my custom vfpage. Can anyone help me over here.
Is standard validation work here..?

Reagrds,
mac
Rowallim TechnologyRowallim Technology
Hii mac admin
You should use this(required="true") in your vfpage.
Hope it will help you.
Mark it as best answer if you got your answer.
Regards
mac adminmac admin
Hi Rowallim Technology,
I have already tried it but i didn't get any result .
brahmaji tammanabrahmaji tammana
Hi mac,

You can try using Javascript validation to achieve this.
Please try with document.getElementById(XXXXX).value (something like this) to get the value of checkbox and use it before saving the record.

Hope it works. I will also try give an example.

Thank you 
Brahma
brahmaji tammanabrahmaji tammana
Hi mac,

Here is the sample code which can make the checkbox mandatory.

I just used javascript validation to achieve this. I am not sure any other solution to achieve this.
<apex:page Controller="MyAccount">
    
    <script>
        function saverecord()
        {
            if(!document.getElementById("{!$Component.fm.pb.pbs.cb}").checked)
            {                    
                alert('Dude, Select the checkbox');
            }
            else
            {
                Saveit();
            }
        }    
    </script>
    
<apex:form id='fm'>
    <apex:pageBlock id="pb">
        <apex:pageBlockSection id="pbs">
            <apex:inputField value="{!Account.name}" id="ac"/>
            <apex:inputCheckbox id="cb" ></apex:inputCheckbox>            
        </apex:pageBlockSection>       
        <apex:pageBlockButtons>
            <apex:commandButton value="Save" onclick="saverecord()" />
        </apex:pageBlockButtons>
    </apex:pageBlock>
    <apex:actionFunction action="{!WriteyourOwnMethod}"  name="saveit"  />
</apex:form>        
</apex:page>


Thanks,
Brahma