Skip to main content
Participant
October 1, 2008
Answered

"checked" not working in cfinput

  • October 1, 2008
  • 1 reply
  • 325 views
Hi

I'm fairly new to Coldfusion but making reasonable progress. However, I've got a problem with cfinput in a cfformgroup. There are several checkboxes in the group and I want to have one of them checked when the form appears. Weirdly, this was working at one point but after making changes in other parts of the form, it stopped working. Unfortunately I didn't notice when this happened but there have been no changes to the code within the form group. I'm fairly convinced this must be a bug in CF but can anyone offer any suggestions (all gratefully received).

Code of the form group is this:

<cfformgroup type="vertical">
<cfinput type="checkbox" name="publishphone1" id="publish01" value="Y">
Publish phone 1<br />
<cfinput type="checkbox" name="publishphone2" id="publish02" value="Y">
Publish phone 2<br />
<cfinput type="checkbox" name="publishmobile" id="publish03" value="Y">
Publish mobile<br />
<cfinput type="checkbox" name="publishfax" id="publish04" value="Y">
Publish fax<br />
<cfinput type="checkbox" name="publishemail" id="publish05" value="Y" checked="yes">
Publish e-mail<br />
</cfformgroup>


Thanks - Roger
This topic has been closed for replies.
Correct answer r3res
Dan

Many thanks for that, but it didn't work either! However, I've had a play with this and changed the cfinput to plain input tags:

<cfformgroup type="vertical">
<input type="checkbox" name="publishphone1" value="Y">
Publish phone 1<br />
<input type="checkbox" name="publishphone2" value="Y">
Publish phone 2<br />
<input type="checkbox" name="publishmobile" value="Y">
Publish mobile<br />
<input type="checkbox" name="publishfax" value="Y">
Publish fax<br />
<input type="checkbox" name="publishemail" value="Y" checked>
Publish e-mail<br />
</cfformgroup>

...and this works fine. I noticed that the in-line editor for cfinput gives the options of 'yes' and 'no' for checked - but if you use the tag editor pop-up, where you actually use a checkbox for 'checked', it generates the code checked="true" - so definitely something not right here. The cfinput checked="yes" works fine for radio buttons but apparently not for checkboxes. At least not consistently anyway.

Thanks for your help all the same - it helped to finally inspire a solution.

Roger

1 reply

Inspiring
October 1, 2008
not sure about flash forms, but with html forms it's checked="checked", not checked="yes"
r3resAuthorCorrect answer
Participant
October 1, 2008
Dan

Many thanks for that, but it didn't work either! However, I've had a play with this and changed the cfinput to plain input tags:

<cfformgroup type="vertical">
<input type="checkbox" name="publishphone1" value="Y">
Publish phone 1<br />
<input type="checkbox" name="publishphone2" value="Y">
Publish phone 2<br />
<input type="checkbox" name="publishmobile" value="Y">
Publish mobile<br />
<input type="checkbox" name="publishfax" value="Y">
Publish fax<br />
<input type="checkbox" name="publishemail" value="Y" checked>
Publish e-mail<br />
</cfformgroup>

...and this works fine. I noticed that the in-line editor for cfinput gives the options of 'yes' and 'no' for checked - but if you use the tag editor pop-up, where you actually use a checkbox for 'checked', it generates the code checked="true" - so definitely something not right here. The cfinput checked="yes" works fine for radio buttons but apparently not for checkboxes. At least not consistently anyway.

Thanks for your help all the same - it helped to finally inspire a solution.

Roger
Inspiring
October 1, 2008
r3res wrote:
> I noticed that the in-line editor for cfinput gives
> the options of 'yes' and 'no' for checked - but if you use the tag editor
> pop-up, where you actually use a checkbox for 'checked', it generates the code
> checked="true" - so definitely something not right here.

I think you maybe misunderstanding the relationship between <input..>
and <cfinput...> tags.

The <input...> tag is an HTML tag that is delivered to the client which
then render to the user according to the appropriate standard.

The <cfinput...> tag is a CFML tag that calls built in ColdFuison
functions that ultimately -- after much processing -- builds an HTML
<input...> tag.

Thus if you put <cfinput checked="yes"...> you are telling the CFM
function to render an <input...> tag with a check parameter, which it
will do so according to the HTML standard to which you are building your
pages.

I just tested that using <cfinput checked="yes"...> on my XHTML 1.0
strict test page generated an <input checked="checked"...> HTML tag.