/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Code works in FF but not IE

The Following works in FireFox but not in Internet Explorer. Can anyone shed some light on the issue?

[CODE]function showTab(tab)
{
var element;
if( document.getElementById )
{
element = document.getElementById(“tab”+tab );
element.style.display = ‘block’;

for(var i=1; i < 6; i=i+1)
{
element2 = document.getElementById(“tab”+i);
if(document.getElementById(“tab”+i) == null)
{alert(“tab “+i+” is null”);}
if(i != tab)
{
element2.style.display = ‘none’;
}
}
}
else
{
alert(‘couldn’t find ID’);
}
}[/CODE]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 23.2009 — we need to see the whole picture, HTML included
Copy linkTweet thisAlerts:
@rwc0524authorJul 23.2009 — Oh yeah! So the java script code is above and the html code where I call the JS function is shown below.

[CODE]
<body class="largeBod" onLoad="show5Tab(1);">
[/CODE]

This is to hide the unwanted divs when the page loads. Then below is code for the mapped image so that each tab is clickable and will show that tab and hide the others.

[CODE]
<map name="Map1">
<area class="hand" shape="rect" coords="271,16,396,47" onClick="javascript:show5Tab(1);">
<area class="hand" shape="rect" coords="395,16,513,47" onClick="javascript:show5Tab(2);">
<area class="hand" shape="rect" coords="513,16,633,47" onClick="javascript:show5Tab(3);">
<area class="hand" shape="rect" coords="632,16,752,47" onClick="javascript:show5Tab(4);">
<area class="hand" shape="rect" coords="752,16,875,47" onClick="javascript:show5Tab(5);">
</map>
[/CODE]


Hope that is enough
Copy linkTweet thisAlerts:
@KorJul 23.2009 — Get rid of the condition:
<i>
</i>if( document.getElementById )

All the modern browsers use getElementById() method.

And the elements with the id="tab1", id="tab1"... can we see them? What are they?
Copy linkTweet thisAlerts:
@rwc0524authorJul 23.2009 — OK I took out the conditional and it still works in FF so that is good. Below is HTML that has the id tags

[CODE] <div id="tab1">
<img src="images/seashore/tabs1.gif" border="0" usemap="#Map1" />
<br><br>
<table><tr><td><img src="images/seashore/seashoreExterior1.jpg" /></td><td>Price</td></tr></table>
</div>

<div id="tab2">
<img src="images/seashore/tabs2.gif" border="0" usemap="#Map1" />
<br><br>
<table><tr><td><img src="images/seashore/seashoreExterior1.jpg" /></td><td>Details</td></tr></table>
</div>

<div id="tab3">
<img src="images/seashore/tabs3.gif" border="0" usemap="#Map1" />

<table style="padding-top:5px"><tr><td>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="900" height="550" id="seashore_gallery" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="flashGallery/seashore_gallery.swf" /><param name="quality" value="high" /><param name="wmode" value="opaque" /><param name="bgcolor" value="#cccccc" />
<embed src="flashGallery/seashore_gallery.swf" quality="high" wmode="opaque" bgcolor="#cccccc" width="900" height="550" name="seashore_gallery" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>

</td></tr></table>
</div>

<div id="tab4">
<img src="images/seashore/tabs4.gif" border="0" usemap="#Map1" />
<br><br>
<table><tr><td><img src="images/seashore/seashoreExterior1.jpg" /></td><td>Location</td></tr></table>
</div>

<div id="tab5">
<img src="images/seashore/tabs5.gif" border="0" usemap="#Map1" />
<br><br>
<table><tr><td><img src="images/seashore/seashoreExterior1.jpg" /></td><td>Part Ownership</td></tr></table>
</div> [/CODE]
Copy linkTweet thisAlerts:
@rwc0524authorJul 23.2009 — Thank you for all your help but I found the problem. Simply enough it was the way that I was calling my external javascript file.

Apparently IE does not like it when you use type="application/javascript". I took it out and everything works perfectly.
×

Success!

Help @rwc0524 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...