...

View Full Version : Firefox ignoring a portion of small function



RexxCrow
08-22-2007, 10:06 AM
The highlighted portion is ignored and I feel it has something to do with the about and contact, but am at a loss as to how to remedy this, I can get it to work in IE but that is all (by removing the ' ''s from that text), any ideas as to were my flaw(s) are in in this function? TIA


<script language="javascript" type="text/javascript"><!--
function goVis(swap){
getV=document.getElementById(swap)
if(getV=='contact'&&about.style.display=='block'){
about.style.display='none'
}
if(getV=='about'&&contact.style.display=='block'){
contact.style.display='none'
}
if(getV.style.display=='none'){
getV.style.display='block'
}else{
getV.style.display='none'
}
}
//--></script>

mcjwb
08-22-2007, 10:40 AM
document.getElementById() will return an object (if it finds one and null if it doesn't) so getV=='contact' and getV=='about' will always be false. Try alert(getV); to proove this.

You could do something like this:

<script type="text/javascript"><!--
function goVis(swap){
var getV=document.getElementById(swap); //returns an object.

if(swap=='contact'&&document.getElementById('about').style.display=='block'){
document.getElementById('about').style.display='none';
}
else if(swap=='about'&&document.getElementById('contact').style.display=='block'){
document.getElementById('contact').style.display='none';
}
if(getV.style.display=='none'){
getV.style.display='block';
}else{
getV.style.display='none';
}
}
//--></script>

I've not tested it, but I think it should work.

RexxCrow
08-22-2007, 10:57 AM
Alright that worked like a charm, thanks for the help on that, so strings and objects don't mix then; I knew it had something to do with the string, though I thought I had to declare a specific type of variable, well at least I am learning, slowly but surely, heh.

mcjwb
08-22-2007, 05:34 PM
Javascript is a loosely typed language so you can assign anything to any variable.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum