# HTML question

**URL:** <https://www.ruby-forum.com/t/html-question/156759>\
**Category:** Rails\
**Created:** [January 2, 2009, 3:49pm UTC](https://www.ruby-forum.com/t/html-question/156759 "2009-01-02T15:49:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [January 2, 2009, 3:49pm UTC](https://www.ruby-forum.com/t/html-question/156759/1 "2009-01-02T15:49:27Z")

</div>

if you are offended by HTML questions on this list, please feel free to  
flame me off list.

I would like to display a boolean value in my #index view as a checkbox  
that  
is checked when true and blank when not true. Is there some markup that  
can  
do this? Is it “legal” to embed an tag outside  
the  
context of a form? Even if it’s “legal”, is it considered bad practice?

I’ve poked around a little looking to see what others have done, and I  
could  
embed a checkmark image in my page, or I could embed the proper Unicode  
code  
for a checkmark, and hope that the browser has a font installed with  
that  
character, but it seems to me that the browser must already know how to  
display a checkmark, and in the principle of DRY, I should be able to  
reuse  
it 🙂

–wpd

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [January 2, 2009, 4:01pm UTC](https://www.ruby-forum.com/t/html-question/156759/2 "2009-01-02T16:01:10Z")

</div>

On 2 Jan 2009, at 14:48, Patrick D. wrote:

> if you are offended by HTML questions on this list, please feel free  
> to flame me off list.
> 
> I would like to display a boolean value in my #index view as a  
> checkbox that is checked when true and blank when not true. Is  
> there some markup that can do this? Is it “legal” to embed an  
> tag outside the context of a form? Even if  
> it’s “legal”, is it considered bad practice?

w3c validator doesn’t seem to mind.

Fred

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [January 2, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/html-question/156759/3 "2009-01-02T16:08:13Z")

</div>

Frederick C. wrote:

> > I would like to display a boolean value in my #index view as a  
> > checkbox that is checked when true and blank when not true. Is  
> > there some markup that can do this? Is it “legal” to embed an  
> > tag outside the context of a form? Even if  
> > it’s “legal”, is it considered bad practice?
> 
> w3c validator doesn’t seem to mind.

Under what DOCTYPEs?

(BTW I am building a webpage for a new project - non Rails - with  
generated  
source. The very first time I ran it thru [http://validator.w3.org/](http://validator.w3.org/) , it  
passed  
without even a warning. Beat that, Rails!!)

–  
Phlip

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [January 2, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/html-question/156759/4 "2009-01-02T16:39:16Z")

</div>

> > character, but it seems to me that the browser must already know how to

Thanks Michael, Philp, & Fred. I should have thought of just trying it  
and  
running it through the validator before asking. Next time, I’ll try  
that  
first.

FWIW, when I mentioned “DRY” I was referring to reusing the code in the  
browser that displays a checkmark, not to any code that I might have  
written  
in my application. It was supposed to be a joke, but I guess it died.  
Sigh.

Thanks again folks. I appreciate the tips and opinions. Please keep  
them  
coming.

–wpd

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [January 2, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/html-question/156759/5 "2009-01-02T16:18:11Z")

</div>

On Fri, Jan 2, 2009 at 8:48 AM, Patrick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if you are offended by HTML questions on this list, please feel free to  
> flame me off list.
> 
> I would like to display a boolean value in my #index view as a checkbox that  
> is checked when true and blank when not true. Is there some markup that can  
> do this? Is it “legal” to embed an tag outside the  
> context of a form? Even if it’s “legal”, is it considered bad practice?

I was able to get formless inputs to pass validation (as XHTML 1.0  
strict or 1.1) at [w3.org](http://w3.org) by putting them inside block elements like  
div or table.

> I’ve poked around a little looking to see what others have done, and I could  
> embed a checkmark image in my page, or I could embed the proper Unicode code  
> for a checkmark, and hope that the browser has a font installed with that  
> character, but it seems to me that the browser must already know how to  
> display a checkmark, and in the principle of DRY, I should be able to reuse  
> it 🙂

While it may not be invalid HTML, I would personally want more control  
over the display of this element. I’d much prefer an image or some  
other indicator (+ or - characters, for instance). Also the checkbox  
control is going to potentially allow the user to select/deselect the  
checkbox, whereas an image will not. And what if you later decide  
you’d rather have happy/sad face icons? 😉

DRY doesn’t really apply here. I suppose you could apply DRY by  
writing a helper function to generate a link to the correct image  
based on the boolean value. But reusing standard elements in ways they  
weren’t really designed to be used… just muddles the semantics.

-Michael

–  
Michael C. Libby  
[www.mikelibby.com](http://www.mikelibby.com)

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [January 2, 2009, 5:58pm UTC](https://www.ruby-forum.com/t/html-question/156759/6 "2009-01-02T17:58:34Z")

</div>

Hmm, I’d advocate that you use images in this place so that people  
know it’s not something that you can interact with. From a usability  
standpoint, if you provide a checkbox that looks like they can  
interact with, they might try. Keep it simple and obvious to the  
end-user.

On Fri, Jan 2, 2009 at 6:48 AM, Patrick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> for a checkmark, and hope that the browser has a font installed with that  
> character, but it seems to me that the browser must already know how to  
> display a checkmark, and in the principle of DRY, I should be able to reuse  
> it 🙂
> 
> –wpd
> 
> >

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
