When I call the script below with prototype.js included in the page, I get a "target has no properties" error message. If I take out prototype, it works fine. Can anyone explain this? function changeTab(chosen) { var x; var tabs = new Array() tabs[0] = "one" tabs[1] = "two" tabs[2] = "three" tabs[3] = "four" tabs[5] = "five" for (x in tabs) { target = document.getElementById(tabs[x]); if (tabs[x] !== chosen) { target.style.backgroundColor = ''#E7F1F8''; } else if (tabs[x] == chosen) { target.style.backgroundColor = ''white''; } } --~--~---------~--~----~------------~-------~--~----~ 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 a different for loop, maybe for(i = 0; i < tabs.length; i++). There has been a ton of discussion on this list lately that for .. in loops are specific to objects, and using them on arrays is just wrong. You might have better luck with a different format for your loop. Walter On Jul 8, 2007, at 8:03 AM, Judson wrote:> > When I call the script below with prototype.js included in the page, I > get a "target has no properties" error message. If I take out > prototype, it works fine. Can anyone explain this? > > > [snip]> tabs[5] = "five" > for (x in tabs) > {--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Walter! That really did the trick. On Jul 8, 7:10 am, Walter Lee Davis <w...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Try using a different for loop, maybe for(i = 0; i < tabs.length; i++). > Therehasbeen a ton of discussion on this list lately that for .. in > loops are specific to objects, and using them on arrays is just wrong. > You might have better luck with a different format for your loop. > > Walter > > On Jul 8, 2007, at 8:03 AM, Judson wrote: > > > > > When I call the script below with prototype.js included in the page, I > > get a "targethasnoproperties" error message. If I take out > > prototype, it works fine. Can anyone explain this? > > > [snip] > > tabs[5] = "five" > > for (x in tabs) > > {--~--~---------~--~----~------------~-------~--~----~ 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 Jul 8, 10:03 pm, Judson <judsonmitch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When I call the script below with prototype.js included in the page, I > get a "target has no properties" error message. If I take out > prototype, it works fine. Can anyone explain this? > > function changeTab(chosen) > { > var x; > var tabs = new Array() > tabs[0] = "one" > tabs[1] = "two" > tabs[2] = "three" > tabs[3] = "four" > tabs[5] = "five"Consider using an Array literal: var tabs = ["one","two","three","four","five"];> for (x in tabs)Prototype.js extends the built-in Array object''s methods, a for..in loop will return those methods too. Use a normal for loop: var target; for (var i=0, len=tabs.length; i<len; i++){ target = document.getElementById(tabs[x]);> { > target = document.getElementById(tabs[x]); > > if (tabs[x] !== chosen) > { > target.style.backgroundColor = ''#E7F1F8''; > } > else if (tabs[x] == chosen) > { > target.style.backgroundColor = ''white''; > }You can replace all that with: target.style.backgroudColor = (tabs[x]==chosen)?''white'':''#E7F1F8''; Though you might try Prototype.js''s Array.prototype.each() method. -- 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 -~----------~----~----~----~------~----~------~--~---
parry.luke-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jul-09 14:26 UTC
Re: Prototype Doesn''t Play Well With Others?
Hey there, Looking at the error it seems that document.getElement.byId() isn''t working, but why aren''t you using the $() helper?, not sure if that causes conflicts. This may be happening because ever the elements don''t exist, named wrong, however you aren''t actually using anything from prototype js, and I would sincerly recommend you look at the api docs. Mr Parry. On Jul 8, 1:03 pm, Judson <judsonmitch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When I call the script below with prototype.js included in the page, I > get a "target has no properties" error message. If I take out > prototype, it works fine. Can anyone explain this? > > function changeTab(chosen) > { > var x; > var tabs = new Array() > tabs[0] = "one" > tabs[1] = "two" > tabs[2] = "three" > tabs[3] = "four" > tabs[5] = "five" > for (x in tabs) > { > target = document.getElementById(tabs[x]); > > if (tabs[x] !== chosen) > { > target.style.backgroundColor = ''#E7F1F8''; > } > else if (tabs[x] == chosen) > { > target.style.backgroundColor = ''white''; > } > }--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
When i was looking over your code it looks as though you''re comparing a literal value where you may be looking for a property of the document element.>> if (tabs[x] !== chosen)chosen is a variable, tabs is an array of string values, how is this intended to work? Perhaps you were looking for a conditional more like if(target.chosen) target.style.backGroundColor= "white" Cheers, Matt On Jul 9, 10:26 am, "parry.l...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <parry.l...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hey there, > > Looking at the error it seems that document.getElement.byId() isn''t > working, but why aren''t you using the $() helper?, not sure if that > causes conflicts. This may be happening because ever the elements > don''t exist, named wrong, > > however you aren''t actually using anything from prototype js, and I > would sincerly recommend you look at the api docs. > > Mr Parry. > > On Jul 8, 1:03 pm, Judson <judsonmitch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > When I call the script below with prototype.js included in the page, I > > get a "target has no properties" error message. If I take out > > prototype, it works fine. Can anyone explain this? > > > function changeTab(chosen) > > { > > var x; > > var tabs = new Array() > > tabs[0] = "one" > > tabs[1] = "two" > > tabs[2] = "three" > > tabs[3] = "four" > > tabs[5] = "five" > > for (x in tabs) > > { > > target = document.getElementById(tabs[x]); > > > if (tabs[x] !== chosen) > > { > > target.style.backgroundColor = ''#E7F1F8''; > > } > > else if (tabs[x] == chosen) > > { > > target.style.backgroundColor = ''white''; > > } > > }--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---