/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Show/Hide script fails in IE

I’ve been searching for a specific answer for this for some time so I wouldn’t have to bother anyone with this, so I hope it’s not too much of a pain here…

I’ve modified this code so that it will show when clicked, while at the same time closing all other “boxes”. In doing so, it is broken for IE. This works without issue in FF and Opera.

I know it has something to do with getElementById, but I don’t know how to solve it. I’ve really tried before I got here. Does anyone have any suggestions?

I am also open to a different method if there is just something stupid I’m missing that would make it that much easier. I’m mainly a web designer and only dabble in java script which I’d like to change.

Thank you very much for your time,
John

[code=php]

<!—- stack_flip.js – modified from online sources –>

function showOrHide(eId, state)
{
if (e = document.getElementById(eId))
{
if (state == null)
{
state = e.style.display == ‘none’;
e.style.display = (state ? ” : ‘none’);
}
if (eId == “box1”) { hideAll1() }
if (eId == “box2”) { hideAll2() }
if (eId == “box3”) { hideAll3() }
if (eId == “box4”) { hideAll4() }
}
}

function hideAll1(){
document.getElementById(‘box1’).style.display = ‘table’;
document.getElementById(‘box2’).style.display = ‘none’;
document.getElementById(‘box3’).style.display = ‘none’;
document.getElementById(‘box4’).style.display = ‘none’;
}
function hideAll2(){
document.getElementById(‘box1’).style.display = ‘none’;
document.getElementById(‘box2’).style.display = ‘table’;
document.getElementById(‘box3’).style.display = ‘none’;
document.getElementById(‘box4’).style.display = ‘none’;
}
function hideAll3(){
document.getElementById(‘box1’).style.display = ‘none’;
document.getElementById(‘box2’).style.display = ‘none’;
document.getElementById(‘box3’).style.display = ‘table’;
document.getElementById(‘box4’).style.display = ‘none’;
}
function hideAll4(){
document.getElementById(‘box1’).style.display = ‘none’;
document.getElementById(‘box2’).style.display = ‘none’;
document.getElementById(‘box3’).style.display = ‘none’;
document.getElementById(‘box4’).style.display = ‘table’;
}

<!———————————>
[/code]

Here is an HTML snippet of the function being called:

[code=php]
<!——– HTML call snippet ——->
<a style=”text-decoration:none” href=”javascript:;” onclick=”showOrHide(‘box4’)” class=”itemLink” style=”text-align:justify”>
<font face=”Arial” color=”maroon” size=”3″><b>Important information</b><br></a>
<div id=”box4″ style=”display:none; width: 300px”>

<!– update an iframe in center of page –>
<div style=”z-index: 19; left: 288px; width: 510px; position: absolute; top: -130px; height: 120px”>
<iframe src=”open_notes.html” width=”510″ height=”1050″ scrolling=”no” frameborder=”0″>
</iframe>
</div>
<!– end iframe –>

<ul>
<li>List of important sub-stuff</li>
<li>More sub-stuff</li>
</ul>
</div>
<!—————————–>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 21.2008 — Change the:

document.getElementById(id).style.display = 'table';

to:

document.getElementById(id).style.display = '';

IE doesn't support the table display values.
Copy linkTweet thisAlerts:
@jmchaffieauthorOct 21.2008 — Good Grief. I should have figured that out by noticing that from the top part of the code, I just overlooked it beating my head against the wall on everything else.

Thank you very much. That fixed it right up and works across the board. Lifesaver.

Thanks again,

John
×

Success!

Help @jmchaffie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...