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
Suresh(Suri)Suresh(Suri) 

How to validate html input checkbox checked/unchecked

Hi,
I have 2 html input checkboxes in vf page i want to validate in commad button action is checked or not based on i want to display error message in page but whe i select check boxes after clicking on submit button am getting null in controller and page refreshing and all checkboxes are unchecked.
this is my page code
<input type="checkbox" id="Checkbox" value="{!Test1}" />
<input type="checkbox" id="Checkbox1" value="{!Test2}" />

<apex:commandButton value="submit" action="{!submitaction}"/>

class code
public Boolean Test1{get;set;}
    public Boolean Test2{get;set;}

public PageReference submitaction()
{  
    system.debug('value'+Test1)
    system.debug('value'+Test2)

Any one can help???
Prabhat Kumar12Prabhat Kumar12
Hi Suresh try Below code.
 
Public class checkboxValidation{

public Boolean Test1{get;set;}
public Boolean Test2{get;set;}

public PageReference submitaction()
{  
    system.debug('value'+Test1);
    system.debug('value'+Test2);
    
    return null;
    
} 

}

VF Page :
 
<apex:page controller="checkboxValidation">

<apex:form>
<apex:inputCheckbox value="{!Test1}" id="indiacheck11"/>
<apex:inputCheckbox value="{!Test2}" id="indiacheck1"/>
<apex:commandButton value="submit" action="{!submitaction}"/>

</apex:form>
</apex:page>

Please let me know if it does not work for you.
Suresh(Suri)Suresh(Suri)
Hi,

Thanks for quick reply but in my page am using some css desining so my requirement is without using apex:form is it possible?
using html check boxes
Prabhat Kumar12Prabhat Kumar12
Apex form is rendered in HTML form. You can use CSS in Apex form also. That will not create any issue.
Suresh(Suri)Suresh(Suri)
Actually these checkboxes are placed inside apex composition define.So i need to validate these checkboxes when i click on submit button.
But am using apex form composition is missing and design layout also changing that is the reason is there any way to use html submit button and validate these checkboxes once both are checked redirect to another page.
can you help me how to approach?
Thanks in advance