Czar.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-27 22:17 UTC
need help with check boxes
Hello everybody, I have created check box in an rhtml file and want to have its id and name of all the items that are checked, in controller class that it is linked to....how can i get it? This is my scenario in rhtml file.... <form action="/admin/list_supplier" method=''POST''> <% i = 0 %> <% @hotels.each do |hotel| %> <input type="checkbox" id="<%=hotel.group_name%>_<%=i%>" name="< %=hotel.group_name%>[<%=i%>]" value= "<%=i%>" onclick="submit">Wanna..Aproove?</td><% i = i + 1 %> <% end %> <input type=''submit'' value=''change to approve''/> The value of @hotels, i am getting from controller where one of the column is group_name. So how can get the id, name and value of the items checked in the concern controller class(admin). Any help would be really appreciated, thanks in advance, Czar Online --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Assuming you have a bunch of checkboxes like this: <div id=''mainform''> <input type="checkbox" id="X_1" name="X1" class=''admin'' value= "1"> <input type="checkbox" id="X_2" name="X2" class=''admin'' value= "2"> </div> You could get the values like this: var myFields = document.getElementsByClassName(''admin'',$(''mainform'')); for(x=0;x<myFields .length;x++) { if($(myFields[x]).checked) { alert(''yeah'') } } On Jul 27, 6:17 pm, "Czar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <Czar.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everybody, > > I have created check box in an rhtml file and want to have its id and > name of all the items that are checked, in controller class that it is > linked to....how can i get it? This is my scenario in rhtml file.... > > <form action="/admin/list_supplier" method=''POST''> > > <% i = 0 %> > <% @hotels.each do |hotel| %> > > <input type="checkbox" id="<%=hotel.group_name%>_<%=i%>" name="< > %=hotel.group_name%>[<%=i%>]" value= "<%=i%>" onclick="submit" > > >Wanna..Aproove?</td> > > <% i = i + 1 %> > <% end %> > > <input type=''submit'' value=''change to approve''/> > > The value of @hotels, i am getting from controller where one of the > column is group_name. > So how can get the id, name and value of the items checked in the > concern controller class(admin). > Any help would be really appreciated, > thanks in advance, > Czar > > Online--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Looks like someone has a case of classitis. [1] Don''t worry about the class names. Use $$(). [2] $$(''#mainform input[type=checkbox]:checked'').each(function (i) { // cosole.log(i.name + i.checked); // whatever }); TAG 1: http://ahsanity.wordpress.com/2007/05/15/divitis-and-classitis-two- new-words-in-my-css-vocabulary/ 2: http://prototypejs.org/api/utility/dollar-dollar On Jul 30, 2007, at 2:09 PM, Diodeus wrote:> > Assuming you have a bunch of checkboxes like this: > > <div id=''mainform''> > <input type="checkbox" id="X_1" name="X1" class=''admin'' value= "1"> > <input type="checkbox" id="X_2" name="X2" class=''admin'' value= "2"> > </div> > > You could get the values like this: > > var myFields = document.getElementsByClassName(''admin'',$(''mainform'')); > for(x=0;x<myFields .length;x++) { > if($(myFields[x]).checked) { > alert(''yeah'') > } > }--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---