473,549 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.le ngth == 0 ) {
bID=0;
if(document.loc ation.hash != "") {
BID="item"+docu ment.location.h ash.substr(1);
for(i=0;i<myBlo gs.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=myBl ogs[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",it em000208,"Poetr y 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 1644
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.le ngth == 0 ) {
bID=0;
if(document.loc ation.hash != "") {
BID="item"+docu ment.location.h ash.substr(1);
for(i=0;i<myBlo gs.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=myBl ogs[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",it em000208,"Poetr y Reading", plink000208,\
nlink000208]);
No need for the '\' as a continuation line, just put a return
after the comma ',':

myBlogs.push(["item000208",it em000208,"Poetr y Reading",
plink000208,nli nk000208]);

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.getEle mentById('item0 00208');
plink000208 = document.getEle mentById('plink 000208');
nlink000208 = document.getEle mentById('nlink 000208');

myBlogs.push(["item000208",it em000208,"Poetr y Reading",
plink000208,nli nk000208]);
</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$255 13$5a62ac22@per-qv1-newsreader-
01.iinet.net.au >, oz****@iinet.ne t.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.le ngth == 0 ) {
bID=0;
if(document.loc ation.hash != "") {
BID="item"+docu ment.location.h ash.substr(1);
for(i=0;i<myBlo gs.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
7088
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 (microsoft.com, cnn.com, etc.) at the W3 Validator; to my surprise none of them passed. Doesn't anyone care anymore, or are the standards more-or-less...
3
1796
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', which basically means they I would be awkward and would insist that things are done properly, so they are bypassing us... We do have some input...
3
1670
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 dissapointment we were looking towards a more positive attitude towards interoperation with third party products. Is it not possible for MS to...
9
1616
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 which implements an interface InterfaceFuBar which contains two functions Fu and Bar. The goal is to do so without resorting to virtual functions. ...
17
2049
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 javascript function i.e. in Head , Body or Below?
23
2460
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 many hacks (tricks to take advantage of browser buggy-ness) and special rules to be remembered in order to make sure that any one page displays...
22
2157
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..." http://www.windowsitpro.com/Article/ArticleID/47208/47208.html?Ad=1 Roy
2
5934
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 code. I use the <pre> tags to ensure that the code, as well as all of the tag formatting, gets transported.
22
13537
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 http-equiv="content-type" content="text/html;charset=utf-8"> <title>Virtual Library</title> <script type="text/javascript">
7
2547
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 third party ecommerce service for hosting its online store. A few months ago this third party commerce site began using PGP file encryption on XML...
0
7524
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.