View Full Version : Javascript errors

07-06-2007, 04:25 AM
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:

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"; }

<div id="one"><ul>

<li><h2><?php _e('Categories'); ?></h2></li>


<?php wp_list_cats('sort_column=name&optioncount=1'); ?>

<div id="two">
<li><h2><?php _e('Archives'); ?></h2>


<?php wp_get_archives('type=monthly'); ?>



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!


07-06-2007, 04:35 AM
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")

07-06-2007, 05:29 AM
Your posted HTML does not include the third division with the id of 'three' that your script is looking for.