473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

document.getElementById( ....

Good Morning everybody,

I'm trying to adapt a tutorial script that will handle the behaviour of an
"Expanding/Contracting" site-navigation menu. The code that seems to
handle the expansion and contraction follows at the bottom of my
message here.

This following line is a big part of my hang-up:

document.getElementById('m1').style.display='none' ;

Question #1:
My "assumption" is that this statement line will "Contract" the menu-chain
that is named by 'm1' and the action word is 'none'.
My other 'assumption' is that the other statement line would " Expand" the
named menu-chain and the action word is 'block'.
That doesn't make sense but really, what do I know?

Am I correct in my assumptions?

Question #2: ( This is my biggie )
At the end of the day, I want the menu.shtml page to open with
this menu in a fully contracted state. Display only the major
category headings. I took all of the document.getElementById
statements and placed them in a function called CloseAll(), like this:

function CloseAll()
{
document.getElementById('m1').style.display='none' ;
document.getElementById('m2').... // did this for each menu-chain
}

Placed this tag in the menu.shtml
<BODY onLoad="CloseAll()">
but...
When I load the page... nothing displays... NADA, ZILCH.
If I remove the onLoad part, he page displays, but the
menu is FULLY expanded.

Clearly, I am working this code wrong, can someone please help
me sort it out? I've been kicking this thing around for so long that
I barely remember to eat.

Many thanks

-Paul-
[ All of this in now located in the "JS" file ]
document.getElementById('m1').style.display='none' ;
document.getElementById('m2').style.display='none' ;
document.getElementById('m3').style.display='none' ;
document.getElementById('m4').style.display='none' ;
document.getElementById('m5').style.display='none' ;
document.getElementById('m6').style.display='none' ;
document.getElementById('m7').style.display='none' ;
document.getElementById('m8').style.display='none' ;
document.getElementById('m9').style.display='none' ;

var Ary=new Array();
function toggle(list){
var listElement=document.getElementById(list);
for (i=0;i<Ary.length;i++){
if (Ary[i]!=listElement){
Ary[i].style.display="none";
}
}
if (listElement.style.display=="none"){
listElement.style.display="block";
}
else {
listElement.style.display="none";
}
if (!listElement.dis){
listElement.dis=1;
Ary[Ary.length]=listElement;
}
}

Jul 23 '05 #1
7 5953


PaulB wrote:

This following line is a big part of my hang-up:

document.getElementById('m1').style.display='none' ;

Question #1:
My "assumption" is that this statement line will "Contract" the menu-chain
that is named by 'm1' and the action word is 'none'.
My other 'assumption' is that the other statement line would " Expand" the
named menu-chain and the action word is 'block'.
That doesn't make sense but really, what do I know?

Am I correct in my assumptions?
Not necessarily, JavaScript is used to change the CSS display property
of HTML elements and CSS 2.1 knows a lots of possible values for the CSS
display property, 'none' will always hide the element so that it does
not consume layout space but to show an element different values are
possible depending on the functionality of the element. 'block' is for
block elements, other possible values are 'inline' for inline elements,
'list-item' for list item elements, 'table-row' for table rows and so
on. To make things more complicated the usual cross browser problems
exist, modern browsers like Mozilla or Opera 7/8 are closer to CSS 2.1
than IE 6 is which for instance knows how to render HTML tables so
internally must have some way to distinguish between a table row and a
paragraph but does not support the different display properties. While
IE therefore somehow lets you get away with setting the display of a
table row to 'block' that will mess up the rendering with Mozilla or Opera.
There are different strategies to try to solve all that, one is to set
element.style.display = 'none';
to hide an element but use
element.style.display = '';
to show it as that way the browser's default style sheet kicks in which
has the proper defaults for table rows or table cells or paragraphs or
list items.
Question #2: ( This is my biggie )
At the end of the day, I want the menu.shtml page to open with
this menu in a fully contracted state. Display only the major
category headings. I took all of the document.getElementById
statements and placed them in a function called CloseAll(), like this:

function CloseAll()
{
document.getElementById('m1').style.display='none' ;
document.getElementById('m2').... // did this for each menu-chain
}

Placed this tag in the menu.shtml
<BODY onLoad="CloseAll()">
but...
When I load the page... nothing displays... NADA, ZILCH.
If I remove the onLoad part, he page displays, but the
menu is FULLY expanded.


We need to see the HTML of the page e.g. which element has the id 'm1'
and so on.
Also tell us whether you get any script errors in the script console of
your browser, which browsers you are testing with.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Thanks Martin,

I have attached the Menu.htm so that you can
see the various ID elements.

Thank you so much... this issue is becoming
an obsession with me.

Paul
Jul 23 '05 #3
Thanks Martin,

I have attached the Menu.htm so that you can
see the various ID elements.

Thank you so much... this issue is becoming
an obsession with me.

Paul
Jul 23 '05 #4
On 29/06/2005 17:17, PaulB wrote:
I have attached the Menu.htm so that you can
see the various ID elements.


This is a text-only newsgroup. Do /not/ post attachments (my news server
rejected it).

Post a URL, or include code in your post if really necessary.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
Thanks for the offer Martin, bit I can not send an attachment through
this newsgroup. It will be stripped by the server.

-Paul-
Jul 23 '05 #6


PaulB wrote:
Thanks for the offer Martin, bit I can not send an attachment through
this newsgroup. It will be stripped by the server.


What offer? Nobody told you to send an attachment, it suffices if you
quote the relevant HTML. Or you can post a URL as already suggested.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #7
I'm sorry Martin.
I had thought you offered to help and asked to see the HTML stuff.

My apologies and I'll leave you alone about it all

Regards,

Paul
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
1
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
5
by: garfy | last post by:
Hi i get this error in validation Line 22 column 6: document type does not allow element "title" here. <title>Seo Web Design Los Angeles - Web Design And Search Engine Optimization L ...
6
by: therig | last post by:
I'm having issues, I've spent many hours searching and I'm a noob at javascript, any help will be greatly appreciated. I keep getting the following error: Error: document.forms.sec11_A has no...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.