Hi all,

I'm not overly proficient at Javascript, but have fumbled my way through some tutorials to come up with the following code to create a tab mechanism.

It works perfectly in Firefox, Safari, Chrome and IE8. However, in IE6 and IE7 it fails to operate as of the 'for (var i in temp) {' line. It doesn't error out, it just doesn't perform any of the functions within the for.

Some things I've noted:
* In Firefox if I alert(i) below the for, then it alerts the numerical value of i correctly through the for loop.
* In IE7, however, alert(i) alerts the value 'toJSON' and nothing more. It never finds 'if (i <= maxlen) {' to be true as a result.

Any thoughts on what's going wrong here?

function toggle_visibility(showid, hideids) {
	$(showid).style.display = 'block';
	// Change CSS
	var newcss = showid.split('_').join('');
	$(newcss).setAttribute("class", "tabselected"); 
	$(newcss).setAttribute("className", "tabselected");

	if (hideids != '') {
		var temp = new Array();
		temp = hideids.split(',');
		var maxlen = (temp.length - 1);
		var i = 0;
		for (var i in temp) {
			if (i <= maxlen) {
				if (temp[i] != showid) {
					$(temp[i]).style.display = 'none';

					var newcss = temp[i].split('_').join('');
					$(newcss).setAttribute("class", "tab2"); 
					$(newcss).setAttribute("className", "tab2");
				}
			} else {
				break;
			}
		}
	}
}

And I'm calling it with

toggle_visibility('tab3', 'tab1,tab2');

have you seen my tab menu script in javascript code snippets section? i like it so much, i use it in professional applications.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.