Forum
Checkbox checked by default
I really thought that this would be simple, but why does:
<perch:input type="checkbox" id="informed" class="myclass" value="Yes, keep me informed" checked="checked" />
not work ?
I've read a bunch of older posts and have tried value="1", default="1" etc etc as suggested, but still no joy. I am running Perch 2.6.3.
I also realise that the client could be helpful and not want this, but they are adamant they want the checkbox checked by default. Using a radio button would look odd in this instance as well...
Any ideas ?
Andy
If you omit
the checkbox is pre-checked.
Simply do not specify value. A value of "on" will be submitted through the form.
No need for the
too.
This is, what it would look like:
You need to have a value. The 'on' will be coming from some browser trying to patch over the fact that the value is missing.
Set the
default
attribute to the same as thevalue
to check it.Okay, so Firfox added that value of 'on'. Thanks for clarifying, Drew.
From your reply Drew, I am assuming you mean that this should work:
This however did not allow the checkbox to be checked by default.
The only time I can actually get things working (browsers used are Firefox 31 and IE 11) is using Nils solution:
This then gives me an 'on' result against the ID if the submitted form still had the checkbox checked, but reading your comment, it seems that default and value should to be used, which makes sense.
Any ideas why it is not working ?
How are you displaying the form?
Hi Drew, sorry for the delay getting back to you.
I am using the forms app and a simple call:
Is this what you mean ?
Which page function are you using?
<?php perch_content('Registration Form'); ?>
How about with
perch_form()
?Makes no difference concerning the checkbox, but now no longer see the 'success' message on submission.
Due to me not using a perch_content call anymore.....
Or
perch_content_custom()
to get the best of both.Still cannot get the checkbox to be pre-checked.
Ohh well, I will look at trying some alternative solution.
Sorry for really late reply.