# Please help with this bit of JS not working in IE...



## ChimpanzeeUK (Jul 31, 2007)

I have a DIV which is

```
shown if a checkbox is checked and hidden when it's not. I've done it with this bit of JavaScript:
[HTML]		function displaySibling( targetId1, targetId2, sourceId){
			target1 = document.getElementById( targetId1 );
			target2 = document.getElementById( targetId2 );
			if (sourceId.checked){
				target1.style.display = "block";
				target2.style.display = "none";
			} else {
				clearSiblingDetails();
				target1.style.display = "none";
				target2.style.display = "block";
			}
		}
```
And this bit of HTML:

```

```
This part works fine, but I added the following part the page because I don't know whether the box will be checked or unchecked when it's loaded:

```
$(document).ready(function(){
		setTimeout("displaySibling('sibling', 'no_sibling', older_sibling)",1250)
		});
```
This uses a bit of JS I got from here which runs the function when the page has finished loading. This works fine in Firefox but not in IE? 

I have also tried:

```
$(document).ready(function(){
		setTimeout("displaySibling('sibling', 'no_sibling', older_sibling)",1250)
		});
```
and

```
$(document).ready(function(){
		setTimeout("displaySibling('sibling', 'no_sibling', 'older_sibling')",1250)
		});
```
If anyone know why this might not work in IE (6) please help?!?


----------



## MMJ (Oct 15, 2006)

```
$(document).ready(function(){
	$('#older_sibling').onclick = function(){
		displaySibling('#sibling', '#no_sibling',  this);
	};
	setTimeout(function(){
		displaySibling('#sibling', '#no_sibling', $('#older_sibling'))
	}, 1250);
});
```


```
function displaySibling( targetId1, targetId2, sourceId){
	var target1 = $( targetId1 )
	,target2 = $( targetId2 );
	if (sourceId.checked){
		target1.style.display = "block";
		target2.style.display = "none";
	} else {
		clearSiblingDetails();
		target1.style.display = "none";
		target2.style.display = "block";
	}
}
```


```

```
If you're using jQuery you might as well use it's excellent DOM methods.


----------



## ChimpanzeeUK (Jul 31, 2007)

MMJ said:


> If you're using jQuery you might as well use it's excellent DOM methods.


Sorry, I don't have much experience with JS and none with JQ. Could you be a bit more specific?

Do you know why what I've done works in FF and not in IE?


----------



## MMJ (Oct 15, 2006)

ChimpanzeeUK said:


> Sorry, I don't have much experience with JS and none with JQ. Could you be a bit more specific?
> 
> Do you know why what I've done works in FF and not in IE?


I'm pretty sure it is because in setTimeout you pass a variable, not a string in the last parameter:



> setTimeout("displaySibling('sibling', 'no_sibling', *older_sibling*)",1250)


Just replace your current code with my code and it should work.


----------



## ChimpanzeeUK (Jul 31, 2007)

MMJ said:


> I'm pretty sure it is because in setTimeout you pass a variable, not a string in the last parameter:
> 
> Just replace your current code with my code and it should work.


Hi. Thanks for your help. But the code you recommended it exactly what I have in place at the moment. Sorry, my first post wasn't very clear, i have tried it with and without ''s.

Any other ideas? :up:


----------



## MMJ (Oct 15, 2006)

ChimpanzeeUK said:


> But the code you recommended it exactly what I have in place at the moment.




On the contrary, the code I posted is very different than your previous code


----------

