For the life of me I cant set my CheckBox to checked at page load. I have tried adding value="true"
and Checked="checked"
after id and still nothing. Any ideas?
<div class="onoffswitch-container"> <span class="onoffswitch-title">Open Inline</span> <span class="onoffswitch"> <input type="checkbox" class="onoffswitch-checkbox" id="inline"> <label class="onoffswitch-label" for="inline"> <span class="onoffswitch-inner" data-swchoff-text="OFF" data-swchon-text="ON"></span> <span class="onoffswitch-switch"></span> </label> </span> </div>
When rendering a page with a checkbox you want selected or checked by default you need to include the 'checked' attribute. There is no required value for the checked attribute. However, per the checkbox specification only an empty value or 'checked' are valid.
Use the defaultChecked prop to set the default checked value of a checkbox in React, e.g. defaultChecked={true} . Input elements with type set to checkbox support the defaultChecked prop for setting a default value. Copied!
Add checked = "checked" to the input you want selected. For XHTML the recommended way is as described. Check HTML manual and W3C to confirm. The markup posted isn't XHTML, so it's logical to use just the simple keyword attribute checked .
The checked attribute is a boolean attribute. When present, it specifies that an <input> element should be pre-selected (checked) when the page loads. The checked attribute can be used with <input type="checkbox"> and <input type="radio"> .
just write "checked" and it works
<input type="checkbox" class="onoffswitch-checkbox" id="inline" checked>
added "true" parameter below, just try it before, and it works for me
<input type="checkbox" class="onoffswitch-checkbox" id="inline" checked="true">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With