On Jul 8, 10:03 pm, Judson <[EMAIL PROTECTED]> 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 [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
-~----------~----~----~----~------~----~------~--~---