Click here to register.
      
IRC banner


     Etcetera > Help with show hide JS

Help with show hide JS

User sandraqu
Date 8/18/2008 3:22 pm
Views 538
Rating 0    Rate [
|
]
Previous · Next
User Message
sandraqu

I have a simple script, that I am getting an eternal object required error with in IE.  this is only a simplified version of the script in an attempt to pin point the issue.  This is an external script being instigated by an removed event in the HTML.

Tips much appreciated.

function toggleDiv(id){
alert(id); // show_hide - correct value for id
obj = document.getElementById(id);
alert(obj); // null -  where id my value go?
if (obj.style.display == "none"){ // this line hits obj. required err
obj.style.display = "";
} else {
obj.style.display = "none";
}
}

--- (Edited on 8/18/2008 3:22 pm [GMT-0500] by sandraqu) ---



Back to Top
Rate [
|
]
 
 
rogier

I'm no javascript expert, but if the variable "obj" isn't declared elsewhere:

function toggleDiv(id){
alert(id);
var obj = document.getElementById(id);
alert(obj);
if (obj.style.display == "none"){
 obj.style.display = "";
}else {
 obj.style.display = "none";
}
}

 

Rogier | United Knowledge
www.unitedknowledge.nl · www.webgui-help.nl

--- (Edited on 19-08-2008 8:16 pm [GMT+0200] by rogier) ---



Back to Top
Rate [
|
]
 
 
sandraqu

rogier, thanks for the reply.

i have a better one for you, the script was working perfectly.  it was complaining because there was no such ID declared in the HTML of that particular article i used to test with.  Bleh bleh... what a brain fart.

Despite the mishap, what I ended up doing was adding a conditional

if ( document.getElementById(id) ) {
//run my script
}

and this did wonders because I was able to use one template style throughout this particular section of the website.

To give a little background: the script (in it's entirety - not shown here) shows and hides Endnotes.  So we have articles, and if someone wants to see the endnotes (both the little numbers within the article, and the actual endnotes at the end of the article) they click 'Show Endnotes' and wallah! Not all documents have endnotes, so the conditional above helps a lot in avoiding error alerts since there's no <div id="#endnote">list of endnotes</div> in some articles.

The script also toggles 'Show Endnotes' to 'Hide Endnotes' when clicked and vice versa; it also shows (or hides) 'Show Endnotes' if <div id="#endnotes"> exists (or not).  They work well as a team.

Just in case anyone has need for it... lemme know.

--- (Edited on 8/19/2008 3:02 pm [GMT-0500] by sandraqu) ---

--- (Edited on 8/19/2008 3:03 pm [GMT-0500] by sandraqu) ---



Back to Top
Rate [
|
]
 
 

Recent Discussions Color Key

Design:

Development:

Et Cetera:

Install/Upgrade:  

Smoketest:

Template Group:


Re: Shortcut of a thread by knowmad - Thu @ 07:33am

Re: Synopsis search results by knowmad - Thu @ 07:21am

Re: Templates workspace site by rogier - Thu @ 04:24am

Re: Templates workspace site by rogier - Thu @ 02:59am

Re: Shortcut of a thread by perlDreamer - Wed @ 11:46pm

Re: Ubuntu Load on Startup by SteveD - Wed @ 04:37pm

Shortcut of a thread by arjan - Wed @ 04:11pm

Re: preventing email spam mailto by lrobinson - Wed @ 03:51pm

preventing email spam mailto by sandraqu - Wed @ 03:39pm

Re: Data Form and Form Controls by martink - Tue @ 11:05am

Re: Synopsis search results by marieken - Tue @ 06:10am

Re: Übersetzungen vor dem nächsten Treffen by koen - Tue @ 04:24am

Re: Übersetzungen vor dem nächsten Treffen - Translations to be done before the next meeting will take place. by bernd - Tue @ 01:15am