Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Storing element Id names in an array?
Old 01-02-2007, 09:11 AM Storing element Id names in an array?
Super Talker

Posts: 124
Name: Chris
Trades: 0
Ok I'm having a problem trying to accomplish what I'm trying to do.

I have 5 tabs that when clicked on display information below them. However my problem is the tabs change when clicked on to a new bg image position. Here is my current function I coded:

Code:
function updateService(current_id) {
    current_id_content = current_id+'_content';
    var tabs = new Array(5);
    
    tabs[0] = "s_design";
    tabs[1] = "s_coding";
    tabs[2] = "s_branding";
    tabs[3] = "s_marketing";
    tabs[4] = "s_multimedia";
    
    
    for(x = 0; x < 5; x++) {
        old_id = tabs[x];
        content_id = old_id+'_content';
        
        alert('Displaying: '+tabs[x]);
        
        document.getElementById(tabs[x]).style.display = 'inline';
        
        if (document.getElementById(content_id).style.display == 'inline') {
        
            document.getElementbyId(tabs[x]).style.backgroundPosition = 'center';
            document.getElementById(tabs[x]).style.borderBottom = '1px solid #cfcfcf';
            document.getElementById(content_id).style.style.display = 'none';
            
            document.getElementById(current_id).style.backgroundPosition = 'bottom';
            document.getElementById(current_id).style.borderBottom = '0';
            document.getElementById(current_id_content).style.display = 'inline';
            return;
        }
    }
}
(Ignore the alert's it was for debugging purposes only)

I tried doing it that way because I'm not sure how I would loop through the elements of the main parent. (These are children in a parent container)

if there is, would it be: document.parentElement.div.style.display; ?

I'm not sure where to go with this.

Anyways, my problem with the above script is that it is treating them as a literal string instead of an actual id name.
__________________
Chris - Trying to help others and learn myself!

Please login or register to view this content. Registration is FREE
ctess is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-02-2007, 10:17 AM Re: Storing element Id names in an array?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
http://www.greenbuildingfest.com/Jav...ndar_ff_mod.js

It's a bit messy but it does illustrate in a few spots how to loop through child nodes.

Play with that. It might help you. It won't work as your answer (I used it to create a calendar with popup divs) but it probably will get you started.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 01-02-2007, 10:23 AM Re: Storing element Id names in an array?
Super Talker

Posts: 124
Name: Chris
Trades: 0
Well I came up with a sorta solution...it's not completely done ...I'm having issues with making the current content hidden...it's saying the display has no properties.

Code:
function updateService(current_id) {
    var tabs = new Array('s_design','s_coding','s_branding','s_marketing','s_multimedia');
    
    for(x = 0; x < tabs.length; x++) {            
        
        if (tabs[x] != current_id.id) {
            var tabs_content = document.getElementById(tabs[x]+'_content');
            document.getElementById(tabs[x]).style.backgroundPosition = 'center';
            document.getElementById(tabs[x]).style.borderBottom = '1px solid #cfcfcf';
            tabs_content.style.display = 'hidden';
        }
            
    }
    
    var c_id_content = document.getElementById(current_id.id+'_content');
    
    current_id.style.backgroundPosition = 'bottom';
    current_id.style.borderBottom = '0';
    c_id_content.style.display = 'inline';
}
__________________
Chris - Trying to help others and learn myself!

Please login or register to view this content. Registration is FREE
ctess is offline
Reply With Quote
View Public Profile
 
Old 01-02-2007, 10:30 AM Re: Storing element Id names in an array?
Super Talker

Posts: 124
Name: Chris
Trades: 0
I'll make a seperate post for this...but my mistake was a very small one. There is no property: hidden for display...that's for visibility. I switched hidden with none and everythign worked. Also I had to make sure my div's were explicitly set.
__________________
Chris - Trying to help others and learn myself!

Please login or register to view this content. Registration is FREE
ctess is offline
Reply With Quote
View Public Profile
 
Old 01-02-2007, 10:31 AM Re: Storing element Id names in an array?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
If I'm reading that code correctly, it looks like you're using the Javascript to hide the tabs initially.

Why not do that in CSS?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 01-02-2007, 10:57 AM Re: Storing element Id names in an array?
Super Talker

Posts: 124
Name: Chris
Trades: 0
http://sephroth.no-ip.info/nvision3/

There is the example of what I am trying to do. I do use some css, but if it is not set explicitly it doesn't work for some odd reason so I did it that way.

I use the :hover for the mouse over's instead of actually using onMouseOver, etc. however I did need javascript to make sure the current tabs were correct, etc. (You have to click the tabs for the information to show up)
__________________
Chris - Trying to help others and learn myself!

Please login or register to view this content. Registration is FREE
ctess is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Storing element Id names in an array?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.80586 seconds with 12 queries