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
Chris MairChris Mair 

Binding CSS Toggle to Checkbox field. Help!?

So I have this code in Visualforce and it renders great, but when I submit the record the value isn't stored in the Checkbox field.  Can anyone let me know what I'm doing wrong?  I could just use a standard checkbox but I really like the look of the CSS Styled Toggle.

Thanks!

                <div class="onoffswitch">
                <input value="{!Registration_Request__c.Reading_A_Z__c}" type="checkbox" name="onoffswitch1" class="onoffswitch-checkbox" id="myonoffswitch1">
                <label class="onoffswitch-label" for="myonoffswitch1">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch"></span>
                </label>
                </input>
                </div>
Himanshu ParasharHimanshu Parashar
Hi Chris,

SFDC bind value to controller if you use apex:inputcheckbox. you can define the styleClass attirbute to put your custom css.

if you still want to use above code then you can bind value to a apex:inputHidden and set value using javascript so that controller read that value while saving.

Makes sense ?

Thanks,
Himanshu
Chris MairChris Mair
Thanks for your response.  Here is a bit of clarification.  I don't believe I can use apex:inputcheckbox with CSS and get it to render as toggle button which is the desired effect.  I understand how to create the apex:inputhidden fields but could you help me understand using the above code how I'd check the hidden boxes with javascript when the toggle button is clicked?