Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript errors

    Hi, I have got some javascript that toggles between two divs to hide and show each. The only problem is that it shows up an error.

    here is the javascript and error message:
    JS
    Code:
     function switch1(div)
     {
      if (document.getElementById('one'))
      {
      var option=['one','two','three'];
      for(var i=0; i<option.length; i++)
      { obj=document.getElementById(option[i]);
      obj.style.display=(option[i]==div)? "block" : "none"; }
      }
     }
    HTML
    Code:
     	<div id="one"><ul>
      	
      		<li><h2><?php _e('Categories'); ?></h2></li>
      			
      			<ul>
      			
      				<?php wp_list_cats('sort_column=name&optioncount=1'); ?>
     			</ul>
      			
     		</ul>
     		</div>
     		<div id="two">
     		<ul>
     		<li><h2><?php _e('Archives'); ?></h2>
     		
     			<ul>
     			
     				<?php wp_get_archives('type=monthly'); ?>
     				
     			</ul>
     		</li>
     		
     		
     	</ul>
     	</div>
     </div>
    and then the error message:

    Obj has no properties

    and it effects the line:

    obj.style.display=(option==div)? "block" : "none"; }


    If you could help it would be great!

    Ricky

  • #2
    New Coder
    Join Date
    Jun 2007
    Location
    VA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure, but the problem may be the way your array is setup, this is from http://jennifermadden.com/javascript/arraySimple2.html

    Dense Arrays
    The previous lesson featured JavaScript array syntax known as simple, or long array notation. While very easy to read and understand, writing a lot of arrays in long notation can become tiresome. Arrays can also be written in shorthand, producing what is known as a dense array.

    In the construction of a dense array, the array constructor and all the array's elements are contained on one line. Its elements are represented only by their data (no array name, brackets, or indices), and serve as parameters to the Array function. Each element is comma delimited, their indices now assumed chronologically.
    var files = new Array("1st.htm", "2nd.htm", "3rd.htm", "4th.htm")

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Your posted HTML does not include the third division with the id of 'three' that your script is looking for.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •