use jquery and bind click event to some calculcation function. you can set some
value or metadata to count with
eg
= check_box_tag 'name', value, checked?, :'data-count' => 123, :class => 'sums'
and you jquery
var result; // global variable
jQuery('.sums').each(function() {
jQuery(this).bind('click', function() {
result+= parseInt(jQuery(this).attr('data-count')) *
(jQuery(this).attr('checked')) ? 1 : -1;
});
});
in data-count you can have the value you want to inc/dec from final result
when user clicks, jquery will evaluate checked state, when checked, it'll
increase the result, when unchecked, it'll decrease
tom
On Jul 24, 2011, at 20:15 , mr ma wrote:
> Hello to everybody!
>
> I have the following code in new.html.erb allowing a user to
> select more questions (item) for creating a questionnaire:
>
> ...
> <% for item in @itemss %>
> <%= check_box_tag "questionnaire[item_ids][]", item.id,
> @questionnaire.items.include?(item) %>
> <a> <%= item.kind %> <span> <%= item.question %> </span> </a>
> - "<%= item.denomination %>" - p.ti <%= item.score %> <br/>
> <% end %>
> ...
>
> I would like to show, while the user is making his choices, the
> calculation of:
> - the number of selected items
> - the sum of the scores (each item has its own score)
>
> any suggestions?
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz
===============================================================================
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.