Array of check boxes and html warning

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

<%= 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

On 8 March 2010 08:55, Andy J. [email protected] 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

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