javascript - what is the difference between 'value' => 'accept', and 'checked' => TRUE, when using function form_checkbox()
I want to set my checkbox to be automatically unchecked when my webpage loads. I am using the function form_checkbox() which has these parameters if you use an array to give the checkbox your desired properties.
$data = array(
'name' => 'newsletter',
'id' => 'newsletter',
'value' => 'accept',
'checked' => TRUE,
'style' => 'margin:10px',
);
echo form_checkbox($data);
which parameter in my array do I alter so that when my page loads for a user the checkbox is unchecked and then the user would have to check the checkbox for that checkbox to become true?
Answer
Solution:
Try
set
'checked' => FALSE,
will generate checkbox uncheckedor you can even remove
'checked'=>,
without this attribute it's by default uncheckedAnswer
Solution:
Think about how the HTML will look:
Now, this will result in a checked box, because
checked
is set.If you don't want that, just set
checked
tofalse
:What do you know, it's not checked ;)