...

View Full Version : show_hide works in ie7, opera9, not ff2



Theophilus
01-09-2007, 10:46 PM
The following code, designed to give browsers the ability to show or hide answers to faqs by clicking the question, works perfectly in ie7 and opera 9. It doesn't, however, work at all in FireFox 2. Does anyone have any suggestions for how to make it work in FF?

Function definition:

<script>
<!--
//IGNORE THIS PIECE OF CODE
function show_hide(element){
if (eval(element+'.style.display=="none"')){
eval(element+'.style.display=""')
}
else
{
eval(element+'.style.display="none"')
}
}
//-->
</script>
Later on, the actual section to be manipulated:

<a href="javascript:show_hide('whatisaim')">Click here to show or hide the answer to this faq.</a><br>
<div id="whatisaim">
This is where the actual text would go, which would be either hidden or shown, toggling each time the href is clicked.
</div>
At the end of the page, before the closing html tag:

<script>whatisaim.style.display='none';</script>
Of course, these last two parts are repeated for each question.
You can find the actual page here: http://www.aiminternational.org/about/faq.htm

TripperTreats
01-09-2007, 11:00 PM
I tested this out. You just need a slight change in your show_hide function. Try this one:


function show_hide(element){
element=document.getElementById(element);

if (element.style.display == "none"){
element.style.display = "";
}
else
{
element.style.display = "none";
}
}

Theophilus
01-09-2007, 11:18 PM
Thanks! That worked perfectly!
I also had to change:

<script>whatisaim.style.display='none';</script>
to:

<script>document.getElementById('whatisaim').style.display='none';</script>

Now it works in all three (so long as they have JS enabled).

Thank you SO much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum