0

Hey everyone, I'm working on a web application that's supposed to be compatible with all browsers, yet IE, as usual, is giving me one hell of a headache. I'm posting the code below, it's very straightforward... 3 divs containing ordered lists are made hidden/unhidden via a select menu.

The problem occurs when you select one item from the menu, then selecting another item higher up in the menu.

For example: selecting Super, followed by selecting Standard, makes the numbers in the ordered list all 0's. This doesn't happen in any browser other than IE and I just don't get what I'm doing wrong or why it's doing that. If anybody has an answer I would really appreciate the help... cheers!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
function doit()
{
document.getElementById("list1").style.display="none";
document.getElementById("list2").style.display="none";
document.getElementById("list3").style.display="none";

if(document.getElementById("model").value=="lux") document.getElementById("list2").style.display="block";
else if(document.getElementById("model").value=="super") document.getElementById("list3").style.display="block";
else document.getElementById("list1").style.display="block";
}
</script>
</head>
<body onload="doit()">
		
Model:&nbsp;<select id="model" onchange="doit()">
	<option selected="selected" value="standard">Standard</option>
	<option value="lux">Lux</option>
	<option value="super">Super</option>
</select>
<div id="list1"><ol><li>bla</li><li>bla</li><li>bla</li></ol></div>

<div id="list2"><ol><li>bla</li><li>bla</li><li>bla</li><li>bla</li></ol></div>

<div id="list3"><ol><li>bla</li><li>bla</li><li>bla</li><li>bla</li><li>bla</li></ol></div>


</body>
</html>
3
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by matricol
0

aPPmaSTer, mySelectMenu.value is not universally understood.


Use the longwinded mySelectMenu[mySelectMenu.selectedIndex].value instead.

Try this:

function doit()
{
	var model = document.getElementById("model");
	var list1 = document.getElementById("list1");
	var list2 = document.getElementById("list2");
	var list3 = document.getElementById("list3");
	
	if(model && list1 && list2 && list3) {
		var val = model[model.selectedIndex].value;
		list1.style.display = (val == "standard") ? 'block' : 'none';
		list2.style.display = (val == "lux") ? 'block' : 'none';
		list3.style.display = (val == "super") ? 'block' : 'none';
	}
}

Airshow

Edited by Airshow: n/a

0

Thanks, but that wasn't the problem... I still get the 0's when I change values from the menu... :(

0

Then either something else is changing the values to 0's, or some other select menu is being shown. There's nothing in your code nor mine that should cause 0's.

To help diagnose, leave all three select menus showing (comment out the ...display='none' statements) to make the behaviour more observable. If you like, change backgroundColor to indicate the chosen element instead.

Airshow

0

When all three are exposed the numbers are shown properly, only when they're hidden and then exposed again do they start to show 0's. I just can't figure it out...

0

"Stranger and stranger", said Alice.

I will see if I can replicate the symptoms then run some tests.

But first, must get father to the garden centre. He's 87 and gave up driving a while back.

Airshow

1

aPPmaSTer,

Yes I can reproduce the symptoms in IE9.

It's got to be an IE bug but I have worked out a workaround based on the principle that the last list always displays correctly. By moving the selected list to the last position, everything comes right.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
onload = function() {
	var model = document.getElementById("model");
	var listWrapper = document.getElementById("listWrapper");
	var lists = [
		document.getElementById("list1"),
		document.getElementById("list2"),
		document.getElementById("list3")
	];
	function doit() {
		listWrapper.appendChild(lists[model.selectedIndex]);//move the selected list to be last in its containing div.
		for(var i=0; i<lists.length; i++) {
			if(lists[i]) {
				lists[i].style.display = (i == model.selectedIndex) ? 'block' : 'none';
			}
		}
	}
	if(model) {
		model.onchange = doit;
		doit();
	}
};
</script>
</head>
<body>

Model:&nbsp;<select id="model">
	<option selected="selected" value="standard">Standard</option>
	<option value="lux">Lux</option>
	<option value="super">Super</option>
</select>
<div id="listWrapper">
	<ol id="list1"><li>bla</li><li>bla</li><li>bla</li></ol>
	<ol id="list2"><li>bla</li><li>bla</li><li>bla</li><li>bla</li></ol>
	<ol id="list3"><li>bla</li><li>bla</li><li>bla</li><li>bla</li><li>bla</li></ol>
</div>

</body>
</html>

Airshow

Votes + Comments
thanks!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.