On Nov 11, 4:09 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> i try this
>
>         getDaySum: function()
>                 {
>                 var elements = $$('[id^="daysum["]');
>                 var vars = "";
>                 var datum = "";

Here datum is declared as a local variable of the anonymous function
assigned as the value of the getDaySum property.

>                 for (i = 0; i < elements.length; i++)
>                         {
>                         datum = elements[i].id.substring(7,17);

Here you set the value of datum on each loop.


>                         vars = '&datum=' + datum;
>
>                         new 
> Ajax.Request('index.php?m=arbeitszeiten&c=getTagessumme'+vars,
>                                 {
>                                 evalScripts:true,
>                                 onSuccess: function(transport)

The function assigned to the value of the onSuccess property has all
the "outer" function's variables on its scope chain, so...

>                                         {
>                                         var response = transport.responseText;
>                                         $('daysum['+datum+']').innerHTML = 
> response;

...here datum is a reference to the datum you declared above - you
have a closure.  All your onSuccess anonymous functions reference the
same datum variable, so they all get the same value at any given time.

You need to break the closure, try something like:

  onSuccess: (function(datum) {
    return function(transport) {
      var response = transport.responseText;
      $('daysum[' + datum + ']').innerHTML = response;
    }
  })(datum),


--
Rob


--~--~---------~--~----~------------~-------~--~----~
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 [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-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to