Hey Jean!
Nitrobear a écrit :> <input id="formation[3]" name="formation[3]"
value="3"
> type="checkbox">Chef de projet en marketing relationnel
> <input id="formation[8]" name="formation[8]"
value="8"
> type="checkbox">Chef de publicité ou media planer
> <input id="formation[1]" name="formation[1]"
value="1"
> type="checkbox">Online Marketing Manager
OK, a few points first:
- ''['' and '']'' are not valid ID characters.
Use something like
formation_3 instead.
- Since you use distinct values for checkboxes (and you''re right!),
use a single name for all of them. If you''re using a Rails or
PHP backend, you''ll have to use ''[]'' at the end of
the name
(e.g. ''formation[]''), in order to automatically get the
checked
values as an array on the server side. For other backends, this
is usually not necessary (e.g. with J2EE you can name it
''formation''
and use request.getParameterValues(''formation'') to access a
String[]
of values).
- If you''re using XHTML, don''t forget to close your input
tags:
<input.... type="checkbox" />
Now, about the need you expressed: do you mean server-side or
client-side? From the server side, using a single field name makes it
very easy. From the client side, let''s assume your checkboxes are in a
form of ID "myForm": getting an array of all the checked values for
this specific information could go like this:
$(''myForm'').getInputs(
''checkbox'',
''formation[]'').invoke(''getValue'').compact()
You see:
1. getInputs will return the specified form elements, extended.
2. invoke will run their getValue method (extended from
Field.getValue) and produce an array of the results.
3. compact will strip null values (unchecked items) from the result
Now, this is a very surgical extraction. If you need to get the whole
form''s serialized value (e.g. for Ajax requests), use stuff like
Form.serialize instead.
''HTH
--
Christophe Porteneuve a.k.a. TDD
"[They] did not know it was impossible, so they did it." --Mark Twain
Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---