javascript - what is the difference between 'value' => 'accept', and 'checked' => TRUE, when using function form_checkbox()

674

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?

331

Answer

Solution:

Try

set'checked' => FALSE, will generate checkbox unchecked

or you can even remove'checked'=>, without this attribute it's by default unchecked

444

Answer

Solution:

Think about how the HTML will look:

<input type="checkbox" name="newsletter" id="newsletter" value="accept"
                                                  checked class="page_speed_853221435" />

Now, this will result in a checked box, becausechecked is set.

If you don't want that, just setchecked tofalse:

<input type="checkbox" name="newsletter" id="newsletter" value="accept"
                                                          class="page_speed_853221435" />

What do you know, it's not checked ;)

People are also looking for solutions to the problem: php - slug its not working in codeigniter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.