Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

div hiding error in FF :/

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

Can anyone suggest why this isn't working in FF?

Code:
<script>
function showhide(id){

 if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "none"){
       obj.style.display = "";
    } else {
       obj.style.display = "none";
    }
    
    if (id != 'title_div') { title_div.style.display = "none"; }
    if (id != 'subheader_div') { subheader_div.style.display = "none"; }    
    if (id != 'lead_div') { lead_div.style.display = "none"; }    
    if (id != 'video_div') { video_div.style.display = "none"; }    
    if (id != 'testimonials_div') { testimonials_div.style.display = "none"; }    
    if (id != 'header_div') { header_div.style.display = "none"; }        
 }
}
</script>

Basically, it all works - appart from the last few lines.

Code:
    if (id != 'title_div') { title_div.style.display = "none"; }

..gives:

Error: title_div is not defined
Source File: Line: 71

Guessing I'm using the wrong format with this bit:
Code:
title_div.style.display

...any suggestions? (I've had a look on google, but couldn't find anything helpful :/)

Cheers

Andy
 
It's because you've never defined "title_div", "subheader_div", "lead_div", "video_div", "testimonials_div", or "header_div" anywhere, but are expecting them to be available to you.

This is bought about by IE letting developers be lazy by providing them with objects that match the IDs of elements on the page.

If you use "getElementById" then you won't have this problem.

P.S. put a "type" attribute in your SCRIPT tag:

Code:
<script[!] type="text/javascript"[/!]>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

Thanks - I was recommended ProtoType.js, by a friend - and using ${"div_name"} = hide;

..works fine now.

Thanks for the reply though :)

Cheers

Andy
 
I would advise Prototype if you need it (i.e. use more than just the "$" function). If that's all you're using, it's 30K of bloat you could do without.

If you're only using "$", you could copy the "$" function into your own page instead to save all that page weight.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

Thanks for the advice - we are using more than just that function - so I guess we should keep it :) (its only on a link addition page, which we're doing some fancy div hiding/showing, depending on what the user wants to add to the site) .. but we're also using a few of the other features too on the site from prototype.js too.

Thanks again

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top