Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input Checkbox checked by default

Tags:

html

css

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> 
like image 404
Igorski88 Avatar asked Dec 10 '17 21:12

Igorski88


People also ask

How do I keep a checkbox checked by default?

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.

How do I set a default checkbox value?

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!

How do I make a checkbox automatically checked?

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 .

Which attribute will make a checkbox selected ticked by default?

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"> .


2 Answers

just write "checked" and it works

 <input type="checkbox" class="onoffswitch-checkbox" id="inline" checked>  
like image 170
Orange Orange Avatar answered Sep 28 '22 03:09

Orange Orange


added "true" parameter below, just try it before, and it works for me

<input type="checkbox" class="onoffswitch-checkbox" id="inline" checked="true">  
like image 35
Peter ID Avatar answered Sep 28 '22 05:09

Peter ID