473,395 Members | 2,222 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,395 software developers and data experts.

Standards compliance and show-hide div

I have a webpage which shows and hides divs as a method of
navigation. It works great in the ever evil IE. It works not so
great (read not at all) in any standards compliant browser. I
haven't ever bothered with standards compliance type stuff before,
but am slowly converting. For now I just want to get things working
on standards compliant browsers, later I'll actually go fully
standards compliant for my web pages. Could someone give me an idea
of what the problem might be?
The function that shows a particular area of the site looks like this
(note that if not fed a value, it determines the section to display
based on an anchor in the url, a requirement for the content
management system that I am using):
<code>
function showBlog(bID) {
if(arguments.length == 0 ) {
bID=0;
if(document.location.hash != "") {
BID="item"+document.location.hash.substr(1);
for(i=0;i<myBlogs.length;i++){
if(myBlogs[i][0] == BID) {
bID=i;
}
}
}
}
if(bID < myBlogs.length) {
myBlogs[bID][1].style.display='block';
}
if(bID != 0) {
pBID = bID - 1;
myBlogs[bID][3].innerHTML="<< "+myBlogs[pBID][2];
} else {
myBlogs[bID][3].style.display='none';
}
if(bID != myBlogs.length-1) {
nBID = bID + 1;
myBlogs[bID][4].innerHTML=myBlogs[nBID][2]+" >>";
} else {
myBlogs[bID][4].style.display='none';
}
}
</code>

Throughout the page little snippets like the following appear which
define (as divs) the various sections to be manipulated:
<code>
<script>
myBlogs.push(["item000208",item000208,"Poetry Reading", plink000208,\
nlink000208]);
</script>
<div class="blogbody" id="item000204" style="display:none;">
</code>

Anyone who can help will be greatly appreciated.
Jul 23 '05 #1
2 1631
John Doe wrote:
I have a webpage which shows and hides divs as a method of
navigation. It works great in the ever evil IE. It works not so [...] The function that shows a particular area of the site looks like this
(note that if not fed a value, it determines the section to display
based on an anchor in the url, a requirement for the content
management system that I am using):
It would be better if you post a minimal example of working code
(at least working in IE). Below are some hints, it gets you
part of the way but I don't have time to fully reverse engineer
your page from the snippets posted.

And please don't use tabs for blocking code, replace them with 2
(preferred) or 4 spaces before posting.
<code>
Is this just for posting here? Ditch it, the correct tag is:

<script type="text/javascript">

function showBlog(bID) {
if(arguments.length == 0 ) {
bID=0;
if(document.location.hash != "") {
BID="item"+document.location.hash.substr(1);
for(i=0;i<myBlogs.length;i++){
You introduce myBlogs without ever declaring it. I presume your
real page does so, I've just guessed at it below.
if(myBlogs[i][0] == BID) {
bID=i;
}
}
}
}
if(bID < myBlogs.length) {
myBlogs[bID][1].style.display='block';
Unless you explicitly want 'block? Set it to '' and you'll get
the default (which, for divs, is block).
}
if(bID != 0) {
pBID = bID - 1;
myBlogs[bID][3].innerHTML="<< "+myBlogs[pBID][2];
innerHTML is not liked very much, it's not part of the W3C spec,
but it is supported by most browsers. It should not be causing
a problem here.
} else {
myBlogs[bID][3].style.display='none';
}
if(bID != myBlogs.length-1) {
nBID = bID + 1;
myBlogs[bID][4].innerHTML=myBlogs[nBID][2]+" >>";
} else {
myBlogs[bID][4].style.display='none';
}
}
</code>
</script>

Throughout the page little snippets like the following appear which
define (as divs) the various sections to be manipulated:
<code>
<script>
Again, ditch <code> and replace with <script ...> as above.
myBlogs.push(["item000208",item000208,"Poetry Reading", plink000208,\
nlink000208]);
No need for the '\' as a continuation line, just put a return
after the comma ',':

myBlogs.push(["item000208",item000208,"Poetry Reading",
plink000208,nlink000208]);

Referring to elements by their ID is an IE thing. You can't
refer to an element with id="item000208" that way, use:

<script type="text/javascript">
item000208 = document.getElementById('item000208');
plink000208 = document.getElementById('plink000208');
nlink000208 = document.getElementById('nlink000208');

myBlogs.push(["item000208",item000208,"Poetry Reading",
plink000208,nlink000208]);
</script>

I have kept the variables global here 'cos I think that's what
you need.
</script>
And here is another error (maybe...) - your script referring to
the div must be after it, otherwise you will be looking for an
element that has likely not loaded into the document yet (but
since your script and div refer to different anchors, this may
not be an error in your real page).
<div class="blogbody" id="item000204" style="display:none;">
</code>


Lastly, I can't see that this page is going to degrade
gracefully at all. Better to ensure your page works without
JavaScript, then add scripting to enhance it. All those hidden
divs can be hidden when the page loads if JS is enabled,
otherwise they should display and be functional.
Come back if you have any more issues, but please post a minimal
(perhaps partially) working example. Otherwise post an
explanation of what you are trying to do and we can help make
it work even better.
--
Fred
Jul 23 '05 #2
Thanks for the pointer (on the code). All I needed was a pointer, I
didn't expect anyone to reverse engineer anything in order to hand me a
solution on a platter. I'm willing to do some of the leg work. I use
getElementById in my coding these days, but didn't when I coded that
page; I imagine that's it. As to the degrading, that's another thing on
the list to fix once it works with the JS (Don't have time to properly
reengineer it from scratch, have to do a little bugfix here, a little
bugfix there, catch as catch can). I'm sure you're right that it is
better to code w/o js first and then with js, but as I said, until
recently I didn't really give a durn about standards et al. Now that I
do, I'm slowly reworking old projects into nice compliance, but the
emphasis is on slowly.

As to the non-functional and extraneous code. I apologize. I know
better than to cut and paste from a content-management generated page.
Should have worked up a demo as I've done in solving the problems of
several other posts here recently.

The <code> tags were simply a human readable way of pointing out that my
cut from the website was beginning. It's a pretty standard convention
everywhere but (apparently) this newsgroup. As the <script> tag in my
second snippet would indicate I do have at least that much understanding
of JS. Besides without a script tag it wouldn't work in IE either. vi
tabstop=2 keeps my spacing neat for me. That's why I sometimes forget
to fix it for others. Again, my apologies.

Also thanks for the tip about display='' to get default functionality.
Doesn't really matter here, but good coding practice and may come in
handy elsewhere.

Thanks!

In article <41f8ddb2$0$25513$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, oz****@iinet.net.auau says...
John Doe wrote:
I have a webpage which shows and hides divs as a method of
navigation. It works great in the ever evil IE. It works not so

[...]
The function that shows a particular area of the site looks like this
(note that if not fed a value, it determines the section to display
based on an anchor in the url, a requirement for the content
management system that I am using):


It would be better if you post a minimal example of working code
(at least working in IE). Below are some hints, it gets you
part of the way but I don't have time to fully reverse engineer
your page from the snippets posted.

And please don't use tabs for blocking code, replace them with 2
(preferred) or 4 spaces before posting.
<code>


Is this just for posting here? Ditch it, the correct tag is:

<script type="text/javascript">

function showBlog(bID) {
if(arguments.length == 0 ) {
bID=0;
if(document.location.hash != "") {
BID="item"+document.location.hash.substr(1);
for(i=0;i<myBlogs.length;i++){


You introduce myBlogs without ever declaring it. I presume your
real page does so, I've just guessed at it below.
if(myBlogs[i][0] == BID) {
bID=i;
}
}
}
}
if(bID < myBlogs.length) {
myBlogs[bID][1].style.display='block';


Unless you explicitly want 'block? Set it to '' and you'll get
the default (which, for divs, is block).
}
if(bID != 0) {
pBID = bID - 1;
myBlogs[bID][3].innerHTML="<< "+myBlogs[pBID][2];

Jul 23 '05 #3

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

Similar topics

162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
3
by: CJM | last post by:
On company in our group is looking at getting their rather basic website redeveloped externally. In typical fashion, they have declared that this project it 'marketing-led' rather than 'IT-led',...
3
by: Jules | last post by:
So with MS looking towards Longhorn Indigo messaging, for Service based Applications Integration, its brief dalience with adoption of industry wide Web Service standards is over. This is a major...
9
by: christopher diggins | last post by:
I would like some feedback if the follow code is standard compliant, and are there any obvious redundancies or inefficiencies? The purpose of the code is to emulate the behaviour of a struct FuBar...
17
by: Ian | last post by:
Hi there, Can anybody tell me where I can find a standards documents like you have in c#. I am trying to write javascript and would like to know what standards are i.e. Where to put the...
23
by: Mario T. Lanza | last post by:
I have been authoring web sites for several years now and recently come to value web standards (as touted by Zeldman and many other web gurus). I have noticed with frustration that there are so...
22
by: Roy Schestowitz | last post by:
Paul Thurrott: "Wilson's (IE Lead Program Manager) post is disappointing because Microsoft doesn't plan to fully support the latest CSS standard in IE 7.0..." ...
2
by: Mr TVTL | last post by:
Hi there, I've created a series of layouts designed to be optimized for search engines, and yet also standards-compliant. The problem isn't in the layouts themselves, but in the display of the...
22
by: Harry Haller | last post by:
Is there any other way apart from: document.compatMode == 'CSS1Compat' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta...
7
by: tempest | last post by:
Hi all. This is a rather long posting but I have some questions concerning the usage of character entities in XML documents and PCI security compliance. The company I work for is using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.