473,394 Members | 1,802 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,394 software developers and data experts.

document.all[...].style is null or not an object

Hi Guys,

Can you please check this code and see whats wrong with it?? I am getting document.all[...].style is null or not an object error.

Any help will be really appreciated.

Thanks

Code
Expand|Select|Wrap|Line Numbers
  1. function toggleDiv(id,flagit) {
  2. if (flagit=="1"){
  3. if (document.layers) document.layers[''+id+''].visibility = "show"
  4. else if (document.all) document.all[''+id+''].style.visibility = "visible"
  5. else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
  6. }
  7.  
  8. else
  9. if (flagit=="0"){
  10. if (document.layers) document.layers[''+id+''].visibility = "hide"
  11. else if (document.all) document.all[''+id+''].style.visibility = "hidden"
  12. else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
  13. }
  14. }
  15.  
Sep 10 '09 #1
7 8072
Hi Guys,

Can you please have a look at this code and see whats wrong with it?? I am getting document.all[...].style is null or not an object error. I tried really hard but can't figure out where I am going wrong with this code.

Any help will be really appreciated.

Thanks

Expand|Select|Wrap|Line Numbers
  1. function toggleDiv(id,flagit) {
  2. if (flagit=="1"){
  3. if (document.layers) document.layers[''+id+''].visibility = "show"
  4. else if (document.all) document.all[''+id+''].style.visibility = "visible"
  5. else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
  6. }
  7. else
  8. if (flagit=="0"){
  9. if (document.layers) document.layers[''+id+''].visibility = "hide"
  10. else if (document.all) document.all[''+id+''].style.visibility = "hidden"
  11. else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
  12. }
  13. }
Sep 10 '09 #2
I am waiting guys. Please help me..........
Sep 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
today there is hardly any need for document.layers or document.all (you only need that for outdated browsers like NN4 or IE4). just use getElementById() (and if you really need that backward compatibility, use getElementById() as first option)
Sep 10 '09 #4
Thanks for your reply Dormilich. I understand that nowdays we dont need to use document.layers or document.all and instead we use document.getElementById but I am not sure how can I edit this script so that I can use document.getElementById instead of document.layers or document.all. I would really appreciate if you could please update my script.

Thanks
Sep 10 '09 #5
Dormilich
8,658 Expert Mod 8TB
a more modern approach
Expand|Select|Wrap|Line Numbers
  1. function toggleDiv(id,flagit) 
  2. {
  3.   var vis, elem;
  4.  
  5.   if (1 == flagit)
  6.   {
  7.     vis = "visible";
  8.   }
  9.   else if (0 == flagit)
  10.   {
  11.     vis = "hidden";
  12.   }
  13.   else
  14.   {
  15.     throw new RangeError("Unknown Flag");
  16.   }
  17.  
  18.   if (elem = document.getElementById(id))
  19.   {
  20.     elem.style.visibility = vis;
  21.   }
  22.   else
  23.   {
  24.     throw new TypeError("Element with id '"+id+"' does not exist.");
  25.   }
  26.   return vis;
  27. }
if you want a function to toggle the visibility, just read the style.visibility property and change it to the opposite value (no need to pass a flag)
Sep 10 '09 #6
Hi Dormilich

Thanks for the code mate really appreciate. I change my code to match yours but this time i am getting different error.
Exception thrown and not caught do you know anything about this mate. Please help me if you can.

Thanks
Sep 11 '09 #7
Dormilich
8,658 Expert Mod 8TB
put the following code around your function

Expand|Select|Wrap|Line Numbers
  1. try 
  2. {
  3.     toggleDiv(…); // with your values
  4. }
  5. catch (e)
  6. {
  7.     alert(e.name+": "+e.message);
  8. }
Sep 11 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
2
by: Gary Mayor | last post by:
Hi, I'm back again. Basically i'm trying to draw a box over an image which is turning out to be a nightmare. The problem i'm getting at the moment is that i'm creating a line with <div which works...
1
by: Leila | last post by:
Folks I have an html file which looks like this: .. .. .. <body onLoad="WindowOnLoad();"> .. ..
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
4
by: ashkaan57 | last post by:
Hi, I am using the following code to show/hide part of an html page. It works in Netscape and Firefox but dies in IE: "Error: document.layers is null or not an object" <style> ..noshow {...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
7
by: dd | last post by:
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly I've been searching for the answer for two hours and I decided to finally post this question. I'm trying to take a...
4
by: bdbeames | last post by:
Could someone help with this? I currently have a rotating picture that I have on our website's main page. This week we decided to add another set of pictures for users to view. The users can...
5
by: ankit1999 | last post by:
I have a problem, everytime i'm run this page http://click2travel.in/index.php i get the this error,,,
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.