Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 10th, 2002, 10:47 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Javascript: How to test whether an object is an object?

I am making a tree menu with infinte sub nodes. Now to do this I'm trying to do it the simplest way possible and so I have two function one that expands and one that collapses.

This is the code so far.

Code:
    function expandMenu(linkId) {
      var x = 0;
      linkId_new = linkId + "_0";
      while(eval(doc + '[linkId_new]' + sty) == [Object]) {
        linkId_new = linkId + "_" + x;
        linkObj = eval(doc + '[linkId_new]' + sty);
        linkObj.display = "block";
        x++;
      }
    }
    
    function collapseMenu(linkId) {
      linkObj = eval(doc + "[linkId]" + sty);
      linkObj.display = "none";
    }
    
    function doIt() {
      var expandValue = form.expandId.value
      var collapseValue = form.collapseId.value
      if(expandValue != "") {
        expandMenu(expandValue)
      }
      if(collapseValue != "") {
        collapseMenu(collapseValue)
      }
    }


now it is very simple i call doIt() and it calls either expand() or collapse().

Now I use this for the actual menus.

Code:
<div id="go_0" class="Level1">
      <img src="images/frames/left/expands-collapses_plus.gif">
        100
      <div id="go_0_0" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_spacer.gif">
          110
      </div>
      <div id="go_0_1" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_plus.gif">
          120
        <div id="go_0_1_0" class="Level3" style="display: none;">
          <img src="images/frames/left/expands-collapses_spacer.gif">
            121
        </div>
        <div id="go_0_1_1" class="Level3" style="display: none;">
          <img src="images/frames/left/expands-collapses_spacer.gif">
            122
        </div>
      </div>
      <div id="go_0_2" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_plus.gif">
          130
        <div id="go_0_2_0" class="Level3" style="display: none;">
          <img src="images/frames/left/expands-collapses_plus.gif">
            131
          <div id="go_0_2_0_0" class="Level3" style="display: none;">
            <img src="images/frames/left/expands-collapses_plus.gif">
              139
            <div id="go_0_2_0_0_0" class="Level3" style="display: none;">
              <img src="images/frames/left/expands-collapses_plus.gif">
                138
              <div id="go_0_2_0_0_0_0" class="Level3" style="display: none;">
                <img src="images/frames/left/expands-collapses_spacer.gif">
                  137
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="go_0_3" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_spacer.gif">
          140
      </div>
    </div>
    <div id="go_1" class="Level1">
      <img src="images/frames/left/expands-collapses_plus.gif">
        200
      <div id="go_1_0" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_plus.gif">
          210
        <div id="go_1_0_0" class="Level3" style="display: none;">
          <img src="images/frames/left/expands-collapses_spacer.gif">
            211
        </div>
      </div>
      <div id="go_1_1" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_spacer.gif">
          220
      </div>
      <div id="go_1_2" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_spacer.gif">
          230
      </div>
      <div id="go_1_3" class="Level2" style="display: none;">
        <img src="images/frames/left/expands-collapses_spacer.gif">
          240
      </div>
    </div>


As you can see very simple. Note how the id="" are

go_0 (root)
go_0_0 (first link)
go_0_0_0 (first sub of first link)
....
go_0_1 (second link)

Now I just want to loop till there are no more subs.
so. i call expand("go_0") what this should do is expand every go_0_x only, no go_0_x_x_x_x, just the first level.

The actual question is how do I test go_0_0 is an actual object.
so in the line:
while(eval(doc + '[linkId_new]' + sty) == [Object])
how do i make it test whether eval(doc + '[linkId_new]' + sty) is a valid object??

Reply With Quote
  #2  
Old September 10th, 2002, 11:01 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I just figured out a way to do this.

just after posting I remembered the try{} catch() {} block
so the following works:
Code:
    function expandMenu(linkId) {
      var x = 0;
      linkId_new = linkId + "_0";
      
      try {
        while(1==1) {
          linkId_new = linkId + "_" + x;
          linkObj = eval(doc + '[linkId_new]' + sty);
          linkObj.display = "block";
          x++;
        }
      }
      catch(Exception) {
      
      }
    }

Reply With Quote
  #3  
Old September 10th, 2002, 11:18 PM
Nigorr Nigorr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Brisbane, Australia
Posts: 78 Nigorr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Is this the best way to do this or is there a better way??

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Javascript: How to test whether an object is an object?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT