# Array of check boxes and html warning

**URL:** <https://www.ruby-forum.com/t/array-of-check-boxes-and-html-warning/184749>\
**Category:** Rails\
**Created:** [March 7, 2010, 11:16pm UTC](https://www.ruby-forum.com/t/array-of-check-boxes-and-html-warning/184749 "2010-03-07T23:16:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 7, 2010, 11:16pm UTC](https://www.ruby-forum.com/t/array-of-check-boxes-and-html-warning/184749/1 "2010-03-07T23:16:13Z")

</div>

Hi

I am using something like the following code to show an array of  
checkboxes within a form

\<% @froglets.each do |froglet| -%\>  
\<%= check\_box\_tag “note[froglet\_ids][]”, froglet.id %\> \<%= h  
froglet.name %\>  
  
\<% end %\>

These get submitted as an array and all works well, except for the  
fact that firebug gives me warnings on the page (anchor  
note\_froglet\_ids\_ is already defined) as all the checkboxes have the  
same name attribute.

Is there an alternative method of achieving display and submit of an  
array of checkboxes that generates fully valid html? Using rails  
2.3.2. I can update rails if it will help.

Colin

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 8, 2010, 9:57am UTC](https://www.ruby-forum.com/t/array-of-check-boxes-and-html-warning/184749/2 "2010-03-08T09:57:06Z")

</div>

> \<%= check\_box\_tag “note[froglet\_ids][]”, froglet.id %\> \<%= h  
> froglet.name %\>
> 
> These get submitted as an array and all works well, except for the  
> fact that firebug gives me warnings on the page (anchor  
> note\_froglet\_ids\_ is already defined) as all the checkboxes have the  
> same name attribute.

How about using something like:

\<%= check\_box\_tag “note[froget\_ids][]”, froglet.id, :id =\>  
“note\_froglet\_id\_#{froglet.id}” %\>

The ID is automatically generated from the name, given that they’re all  
having the same name it’s not surprising they’re all having the same ID.

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 8, 2010, 11:06am UTC](https://www.ruby-forum.com/t/array-of-check-boxes-and-html-warning/184749/3 "2010-03-08T11:06:45Z")

</div>

On 8 March 2010 08:55, Andy J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “note\_froglet\_id\_#{froglet.id}” %\>  
> The ID is automatically generated from the name, given that they’re all  
> having the same name it’s not surprising they’re all having the same ID.

Rather to my surprise this has removed the warnings (it is the html  
validator plugin for FF that is showing the warnings of course, not  
firebug). I am surprised as I thought that the name and id both have  
to be unique and while this fixes the id the names are still the same.  
In fact the error in the validator specifically referred to the name.  
Having fed the source into the w3c validator however it specifically  
complains about the ids not being unique, and treats it as an error  
not a warning, so this may be a deficiency in the validator plugin.

Many thanks for the help.

Colin

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 8, 2010, 11:10am UTC](https://www.ruby-forum.com/t/array-of-check-boxes-and-html-warning/184749/4 "2010-03-08T11:10:51Z")

</div>

> Rather to my surprise this has removed the warnings (it is the html  
> validator plugin for FF that is showing the warnings of course, not  
> firebug).

Always glad to surprise you.

> I am surprised as I thought that the name and id both have  
> to be unique and while this fixes the id the names are still the same.

This is absolutely correct and valid (and the fact that the ids are  
added to  
an array is something that PHP coders have relied on for at least 10  
years -  
I know I was one of them).

> In fact the error in the validator specifically referred to the name.  
> Having fed the source into the w3c validator however it specifically  
> complains about the ids not being unique, and treats it as an error  
> not a warning, so this may be a deficiency in the validator plugin.

I think it must be, there’s no requirement for names to be unique.

Cheers,

Andy
