/    Sign up×
Community /Pin to ProfileBookmark

JavaScript Show/Hide layers in Firefox

This works in IE perfectly as shown in the first screen shot but in the second screen shot (firefox) its having a lot of problems as you can see.

[code]<script language=”JavaScript”>
//INITS
if (navigator.appName == “Netscape”) {
layerRef=”document.layers”;
styleSwitch=””;
}else{
layerRef=”document.all”;
styleSwitch=”.style”;
}
//HIDING AND SHOWING LAYER CODE
function showLayer(layerName, layerIndex)
{
layerIndexInsert = “”;
if (layerIndex != null)
{
layerIndexInsert = “[” + layerIndex.toString() + “]”;
}
eval(layerRef+'[“‘+layerName+'”]’+layerIndexInsert+styleSwitch+’.display=”block”‘);
}

function hideLayer(layerName, layerIndex)
{
layerIndexInsert = “”;
if (layerIndex != null)
{
layerIndexInsert = “[” + layerIndex.toString() + “]”;
}
eval(layerRef+'[“‘+layerName+'”]’+layerIndexInsert+styleSwitch+’.display=”none”‘);
}
</script>[/code]

[code]<script language=”JavaScript”>
function resetBG()
{
<cfLoop query=”getPackageGroups”>
ss<cfoutput>#getPackageGroups.packageGroupID#</cfoutput>.style.backgroundColor=’ffffff’;
</cfloop>

<cfIf adminID NEQ 0>
ss00.style.backgroundColor=’ffffff’;
</cfif>

<cfIf getOptionalProgramsCount.recordCount NEQ 0>
ss0.style.backgroundColor=’ffffff’;
</cfif>
}

function selectClick(radioSelected, rowID, fee, recordID)
{
//alert(recordID);
resetBG();
document.frmMyEventPackage.packageGroupID[radioSelected].checked=true;
rowID.style.backgroundColor=’ffffd9′;

//total = total – currentPackageGroupFee;
//total = total + fee;
total = fee;
document.getElementById(‘total’).innerHTML = “$” + formatCurrency(total);

currentPackageGroupFee = fee;

//loop through seArray and hide/show special events based on association
//hide
for (i = 0; i < seArray.length; i++)
{
//hide
//hideLayer(‘layTime’);
passLayerName = ‘seRowA’ + seArray[i][1];
hideLayer(passLayerName);
passLayerName = ‘seRowB’ + seArray[i][1];
hideLayer(passLayerName);
passLayerName = ‘seRowC’ + seArray[i][1];
hideLayer(passLayerName);
passLayerName = ‘seRowD’ + seArray[i][1];
hideLayer(passLayerName);
}

//show
for (i = 0; i < seArray.length; i++)
{
if(seArray[i][0] == recordID)
{
//show
//alert(seArray[i][0] + seArray[i][1]);
passLayerName = ‘seRowA’ + seArray[i][1];
showLayer(passLayerName);
passLayerName = ‘seRowB’ + seArray[i][1];
showLayer(passLayerName);
passLayerName = ‘seRowC’ + seArray[i][1];
showLayer(passLayerName);
passLayerName = ‘seRowD’ + seArray[i][1];
showLayer(passLayerName);
}
}

//if admin is logged on (the Non-Registrant option will be available),
//and the user selects the Non-Registrant option,
//then hide the Special Events and Optional Programs sections
<cfIf adminID NEQ 0>
if(rowID == “ss00”)
{
hideLayer(“optionalProgramsSection”);
hideLayer(“specialEventsSection”);
}
</cfif>

//if optional programs are on this event (the optional programs section will be available),
//and the user selects the Optional Programs Only option,
//then hide the Special Events section
<cfIf getOptionalProgramsCount.recordCount NEQ 0>

if(rowID == “ss0”)
{

hideLayer(“specialEventsSection”);
}
</cfif>

//reset Special Events
resetSE();
//reset Optional Programs
resetOP();

}

//create array with all package groups and their associated special events
var seArray = [ [ “item 0-0”, “item 0-1”],[ “item 1-0”, “item 1-1” ] ];
<cfQuery name=”getPG_SE_xref” datasource=”#sqldb#”>
select packageGroupID, specialEventID
from OMR_xref_SpecialEvents_PG
where packageGroupID in
(select packageGroupID from OMR_PackageGroups where eventID = 8 and status = 1)
order by packageGroupID
</cfquery>

<cfSet varArray = ‘var seArray = [ ‘>
<cfLoop query=”getPG_SE_xref”>
<cfSet varArray = #varArray# & ‘ [ “#getPG_SE_xref.packageGroupID#”, “#getPG_SE_xref.specialEventID#” ]’>
<cfIf getPG_SE_xref.currentRow NEQ getPG_SE_xref.recordCount>
<cfSet varArray = #varArray# & ‘, ‘>
</cfif>
</cfloop>
<cfSet varArray = #varArray# & ‘ ];’>

#varArray#

//alert(seArray[2][1]);

</script>[/code]

[url]http://img508.imageshack.us/img508/5870/ie9sq.jpg[/url]

[url]http://img508.imageshack.us/img508/4834/firefox1pj.jpg[/url]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 06.2005 — your code is quite old. It must be re-written for modern browsers. document.layers and document.all are not used anymore (well, IE kept document.all as a second aproach), but DOM methods to traverse the document.
×

Success!

Help @Zucchetto 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.6,
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,
)...