...

View Full Version : Hide/Show button works in IE not Firefox



evanseb83
07-16-2010, 09:58 PM
When I click the button, the images hide/show in IE, but this doesn't work in Firefox. I've tried JSLint and JavascriptLint, but haven't figured out what the issue is. Any help would be much appreciated!! This is the code below:

<script language="Javascript">
<![CDATA[
function openConsole(docId, attachmentFileName, name) {
if (window.customOpenConsole) {
customOpenConsole(encodeURIComponent(attachmentFileName), name);
} else {
headerFrame = window.parent.parent.frames["Header"];
if (headerFrame != null && headerFrame.openDocLink != null){
headerFrame.openDocAttachment(docId, attachmentFileName, name);
}
}
}
function STGhide()
{
var x=document.getElementsByName("ImageControlZone");
for(j=0;j<x.length;j++)
{
var imgs = x[j].getElementsByTagName('img');
for(i=0;i<imgs.length;i++)
{
imgs[i].style.display="none";
}
}
var link = document.getElementById("ShowHideButton");
//alert(link.innerHTML)
link.innerHTML ="<img alt='' src='img/hideshow/showimage.gif' border='0' onclick='javascript:STGshow();' />";
}
function STGshow()
{
var x=document.getElementsByName("ImageControlZone");
for(j=0;j<x.length;j++)
{
var imgs = x[j].getElementsByTagName('img');
for(i=0;i<imgs.length;i++)
{
imgs[i].style.display="";
}
}
var link = document.getElementById("ShowHideButton");
link.innerHTML ="<img alt='' src='img/hideshow/hideimage.gif' border='0' onclick='javascript:STGhide();' />";
}

function openDocumentLink(externalId, languageId) {

if (window.parent.openDocLink != null) {
window.parent.openDocLink(externalId, languageId);
} else {
headerFrame = window.parent.parent.frames["Header"];
if (headerFrame != null && headerFrame.openDocLink != null)
{
headerFrame.openDocLink(externalId, languageId);
}
else {
setTimeout("openDocumentLink('"+externalId+"','"+languageId+"')",500);
}
}
}
]]>
</script>

Old Pedant
07-16-2010, 10:38 PM
Why do you recreate the <img> each time???

Why not just toggle, instead?

Can you show this live? You don't show the HTML, so it's a little hard to guess.

Old Pedant
07-16-2010, 10:45 PM
I would have done something like this:


function STGshowhide(image)
{
var doShow = image.src.indexOf("show") >= 0;

var x=document.getElementsByName("ImageControlZone");
for(j=0;j<x.length;j++)
{
var imgs = x[j].getElementsByTagName('img');
for(i=0;i<imgs.length;i++)
{
imgs.style.display = doShow ? "" : "none";
}
}
image.src = "img/hideshow/" + ( doShow ? "hideimage.gif" : "showimage.gif" );
image.alt = doShow ? "hide images" : "show images";
}

And then code the <img> thus:



<img alt="hide images" src="img/hideshow/hideimage.gif" style="border: none;" onclick="STGshowhide([I]this);" />

Old Pedant
07-16-2010, 10:46 PM
Oh, and since the problem is in FireFox, you really need to try Firebug!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum