Hi there, this code works only fine , if i dont embedding the prototype.js in my document: <script type="text/javascript"> var myCheckBox2 = new Array(); myCheckBox2[''Ort''] = new Array("hamburg","berlin","hannover"); myCheckBox2[''Art''] = new Array("programmierung","support"); myCheckBox2[''Kenntnisse''] = new Array("xhtml","perl","php","java"); for (var mycategory in myCheckBox2){ document.write(mycategory+''<br>''); for (i=0;i<myCheckBox2[mycategory].length;i++){ document.write(myCheckBox2[mycategory][i]+''<br>''); } } </script> you can test it and u will get this result: Ort hamburg berlin hannover Art programmierung support Kenntnisse xhtml perl php java but if i embedding the prototype.js in my document , so i get in addition to the result also the line belows: each undefined undefined eachSlice undefined undefined undefined all undefined undefined any undefined undefined collect undefined undefined detect undefined undefined findAll undefined undefined grep undefined undefined undefined include undefined inGroupsOf undefined undefined inject undefined undefined undefined invoke undefined max undefined undefined min undefined undefined partition undefined undefined pluck undefined reject undefined undefined sortBy undefined undefined toArray zip size inspect find undefined undefined select undefined undefined member undefined entries _reverse _each undefined clear first last compact flatten without reduce uniq undefined intersect undefined clone toJSONument i test it with several versions of prototype.js but this doesn''t help to me. whats going wrong? thx kambiz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello Kambiz, You are using the arrays inproperly. Read: http://www.prototypejs.org/api/array "Why you should stop using for...in to iterate (or never take it up)" There is no such thing as a true assoc. array in JavaScript... everything is treated as objects so when you for-in on an Array object, it will iterate over all the properties of the Array object. For-in is still cool to use for Object objects. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try using Hash: http://prototypejs.org/api/hash <div id="categories">Categories <br /></div> <script type="text/javascript" language="javascript" charset="utf-8"> // <![CDATA[ function updateCategory(value) { var categoryHolder = $(''categories''); categoryHolder.update(categoryHolder.innerHTML + value); } var myCheckBox2 = $H({}); myCheckBox2[''Ort''] = ["hamburg","berlin","hannover"]; myCheckBox2[''Art''] = ["programmierung","support"]; myCheckBox2[''Kenntnisse''] = ["xhtml","perl","php","java"]; myCheckBox2.each(function(category) { updateCategory(category.key); updateCategory(category.value.join(''<br />'')); }); // ]]> </script>> Hi there, > > this code works only fine , if i dont embedding the prototype.js in my > document: > > <script type="text/javascript"> > > var myCheckBox2 = new Array(); > myCheckBox2[''Ort''] = new Array("hamburg","berlin","hannover"); > myCheckBox2[''Art''] = new Array("programmierung","support"); > myCheckBox2[''Kenntnisse''] = new Array("xhtml","perl","php","java"); > > > for (var mycategory in myCheckBox2){ > document.write(mycategory+''<br>''); > for (i=0;i<myCheckBox2[mycategory].length;i++){ > document.write(myCheckBox2[mycategory][i]+''<br>''); > } > } > </script> > > you can test it and u will get this result: > > Ort > hamburg > berlin > hannover > Art > programmierung > support > Kenntnisse > xhtml > perl > php > java > > but if i embedding the prototype.js in my document , so i get in > addition to the result also the line belows: > > each > undefined > undefined > eachSlice > undefined > undefined > undefined > all > undefined > undefined > any > undefined > undefined > collect > undefined > undefined > detect > undefined > undefined > findAll > undefined > undefined > grep > undefined > undefined > undefined > include > undefined > inGroupsOf > undefined > undefined > inject > undefined > undefined > undefined > invoke > undefined > max > undefined > undefined > min > undefined > undefined > partition > undefined > undefined > pluck > undefined > reject > undefined > undefined > sortBy > undefined > undefined > toArray > zip > size > inspect > find > undefined > undefined > select > undefined > undefined > member > undefined > entries > _reverse > _each > undefined > clear > first > last > compact > flatten > without > reduce > uniq > undefined > intersect > undefined > clone > toJSONument > > i test it with several versions of prototype.js but this doesn''t help > to me. > > whats going wrong? > > thx > kambiz > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sep 18, 8:38 pm, kambiz <beh...-Mmb7MZpHnFY@public.gmane.org> wrote:> Hi there, > > this code works only fine , if i dont embedding the prototype.js in my > document: > > <script type="text/javascript"> > > var myCheckBox2 = new Array(); > myCheckBox2[''Ort''] = new Array("hamburg","berlin","hannover"); > myCheckBox2[''Art''] = new Array("programmierung","support"); > myCheckBox2[''Kenntnisse''] = new Array("xhtml","perl","php","java"); > > for (var mycategory in myCheckBox2){Prototype.js extends the native Array.prototype object, for..in iterates over all those properties too. To avoid properties on the scope chain, use hasOwnProperty: if (CheckBox2.hasOwnProperty(mycategory)){ // mycategory is a property of CheckBox2, not // somewhere on the scope chain } -- 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 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 -~----------~----~----~----~------~----~------~--~---
Hi, i thank u all for your help. regards Kambiz On 19 Sep., 04:20, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Sep 18, 8:38 pm, kambiz <beh...-Mmb7MZpHnFY@public.gmane.org> wrote: > > > Hi there, > > > this code works only fine , if i dont embedding the prototype.js in my > > document: > > > <script type="text/javascript"> > > > var myCheckBox2 = new Array(); > > myCheckBox2[''Ort''] = new Array("hamburg","berlin","hannover"); > > myCheckBox2[''Art''] = new Array("programmierung","support"); > > myCheckBox2[''Kenntnisse''] = new Array("xhtml","perl","php","java"); > > > for (var mycategory in myCheckBox2){ > > Prototype.js extends the native Array.prototype object, for..in > iterates over all those properties too. To avoid properties on the > scope chain, use hasOwnProperty: > > if (CheckBox2.hasOwnProperty(mycategory)){ > // mycategory is a property of CheckBox2, not > // somewhere on the scope chain > } > > -- > 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 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 -~----------~----~----~----~------~----~------~--~---