...

View Full Version : Javascript errors



ricky101
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:
JS

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

<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

ddanatzko
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")

rwedge
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum