Brian Williams wrote:
> i don't believe there is a need to use a class if they share a name 
> i.e. amt[]
>
> should be able to use something along the lines of...
>
> $F('amt').each().invoke(function {......})
> ...
Right on track.  You'll need $$() and inject()--see below.
http://prototypejs.org/api/utility/dollar-dollar
http://prototypejs.org/api/enumerable/inject

- Ken Snyder


var sum = $$('input[name="amt[]"]').inject(0, function(memo, input) {
  memo += input.value;
  return memo;
});


or if you define a sum() method for arrays, you can use pluck():

Array.prototype.sum = function(){
  for (var i = 0, sum = 0; i < this.length; sum += this[i++]);
  return sum;
}

var sum = $$('input[name="amt[]"]').pluck('value').sum();

--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to