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

Firefox getElementById problem

Hi all,

I have a checkbox on my site that needs it's status to be changed dynamically depending on the status of a cookie, the script I have works fine in IE yet not in Firefox, I have tried getElementById, getElementsByName and placing the checkbox in a form and obtaining the element that way but nothing seems to work, Firefox can't seem to find the checkbox.

Here is the code that I am currently using

Expand|Select|Wrap|Line Numbers
  1. function infocheck(){
  2. var disabled = getCookie('disabled');
  3. var box = document.settings.toggle;
  4. var pageid = getCookie('currpage');
  5. if (pageid == pid){
  6.     if (disabled === null){
  7.         box.checked = true;
  8.     }
  9.     else{
  10.         box.checked = false;
  11.     }
  12. }
  13. }
  14.  
any suggestions?

Thanks in advance.
Aug 7 '08 #1
20 2132
RamananKalirajan
608 512MB
Hi Dude, it seems there is nothing problem with the code, just check the mozilla browser property wether the cokkie is enabled or not. Because there are two methods for maintaining a session 1) through Cookies 2) URL rewritting. In most of the browser defaultly cookies will be set disabled. Just check that once.

Regards
Ramanan Kalirajan
Aug 7 '08 #2
acoder
16,027 Expert Mod 8TB
Post the HTML code for the checkbox. Is it just a single checkbox and is the ID unique? Have you checked the error console for errors?
Aug 7 '08 #3
I have cookies enabled and here is the code for the checkbox

Expand|Select|Wrap|Line Numbers
  1. <label for="toggle">Info Bar on/off</label> <input type="checkbox" id="toggle" name="toggle" onclick="barstat()" value="" disabled>
  2.  
Yes it is just a single checkbox with a unique ID

I have also checked the error console and this is what it is displaying "box is null"
Aug 10 '08 #4
acoder
16,027 Expert Mod 8TB
Is the name of the form settings?

"box is null" means that it's not getting the checkbox element. Try using the ID, i.e. box = document.getElementById("toggle").
Aug 10 '08 #5
yes the name of the form is settings and I have tried that but it still comes up with the same error

I have also tried the box outside of a form as well, but to no aveil

it may or may not be worth mentioning that this error seems to pop up on both Firefox 2 and 3
Aug 10 '08 #6
acoder
16,027 Expert Mod 8TB
How and when are you calling the infocheck() function?

Can you post the rest of the relevant code or a version that demonstrates the problem or a link?
Aug 10 '08 #7
The function is being called onload along with some other functions, however the snag is that there is another part of the function which does something else but that works perfectly in both

here is the full code at the moment

Expand|Select|Wrap|Line Numbers
  1. function infocheck(){
  2. var disabled = getCookie('disabled');
  3. var box = document.getElementById('toggle');
  4. var pageid = getCookie("currpage");
  5. if (pageid == pid){
  6.     if (disabled === null){
  7.         box.checked = true;
  8.     }
  9.     else{
  10.         box.checked = false;
  11.     }
  12. }
  13. else{
  14.     /*THIS PART ONWARDS IS WORKING PERFECTLY (somehow)*/if (pageid=="pps"){
  15.         if (getCookie("mpwstat")=="yes"){
  16.             history.back(1);
  17.         }
  18.         else{
  19.             return false;
  20.         }
  21.     }
  22.     else{
  23.         return false;
  24.     }
  25. }
  26. }
  27.  
and this is how it is being called, I had to use a custom onload function because of other scripts

Expand|Select|Wrap|Line Numbers
  1. load(setTimeout('infocheck()',1));
  2.  
I think that is all that may be needed let me know if you need any more

P.S. Cannot provide a link as it is not hosted yet
Aug 10 '08 #8
acoder
16,027 Expert Mod 8TB
Can you post the getCookie function code too. What's the value of pid?
Aug 10 '08 #9
the value of pid is pref

getCookie function:
Expand|Select|Wrap|Line Numbers
  1. function getCookie(cookie_name){
  2.   var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
  3.  
  4.   if (results){
  5.     return (unescape(results[2]));
  6. }
  7.   else{
  8.     return null;
  9. }
  10. }
  11.  
Aug 10 '08 #10
acoder
16,027 Expert Mod 8TB
Hm, ok, the best thing would be for you to post the whole code for the page leaving out the irrelevant parts (test it to see if the problem still occurs). If it's too much code, post it as an attachment.
Aug 11 '08 #11
well as far as I can see, all that is relevant to the problem is the coding that was posted earlier, other than the content in the head tags and the declaration the rest is completly irrelevant to the problem.

I will post the declaration and the head tags anyway.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3.  
  4. <head>
  5. <title>Settings</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <script type="text/javascript" src="js/mpw.js"></script>
  8. </head>
  9.  
error is still occuring

let me know if you need any more :)
Aug 13 '08 #12
acoder
16,027 Expert Mod 8TB
What's in the mpw.js JavaScript file? Are the cookie functions in there? Where is pid set? I think if you could produce a mini-version of the page with all irrelevant code stripped out that still produces the error, that would help pinpoint the error. Add a few alerts in too to check that the values of variables are what you expect (or you could use a debugger such as Firebug).
Aug 13 '08 #13
I have just created a mini version, and it seems to work perfectly, however when I link it up to the main site script (mpw.js) it seems to stop working and starts producing the error again.

I think it may be something to do with the other script that loads onload.

The other script that is being called is the "Obtain HREF's" one that you helped me with before, and when I cancel that out it seems to work ok.

I think it could either be a conflict between this script and the valbeta() script or this script and the custom onload script used.
Aug 13 '08 #14
acoder
16,027 Expert Mod 8TB
Now we seem to be getting somewhere! Can you show the code for the custom onload script?
Aug 13 '08 #15
Here is the custom onload function:

Expand|Select|Wrap|Line Numbers
  1. function load(func) {   
  2.   var oldonload = window.onload;   
  3.   if (typeof window.onload != 'function') {   
  4.     window.onload = func;   
  5.   }
  6.   else{   
  7.     window.onload = function() {   
  8.       if (oldonload) {   
  9.        oldonload();   
  10.       }
  11.       else{   
  12.       func;
  13.       }   
  14.     }
  15.   }   
  16. }
  17.  
Aug 13 '08 #16
acoder
16,027 Expert Mod 8TB
You can avoid using this custom script by using addEventListener/attachEvent. See this link for more information. If that fails to solve the problem, can you remind me of the valbeta script.
Aug 14 '08 #17
Sorry for the delayed response, first time in a while I have been able to check back here

I have looked through the page that you provided and i'm not entirely sure where to put the addEventListener(), in relation to the page or script?

Here is the code for the valbeta script
Expand|Select|Wrap|Line Numbers
  1. function valbeta() {
  2.   var anchors = document.getElementsByTagName('a');
  3.   for (var o = 0; o < anchors.length; ++o){
  4.     anchors[o].onclick=function(){
  5.       validate(this.getAttribute('href',2));
  6.       return false;
  7.     };
  8.   }
  9. }
  10.  
Sep 12 '08 #18
acoder
16,027 Expert Mod 8TB
It's been so long that I forgot what this was about.

To use addEventListener/attachEvent is easy. Wherever you would call your custom onload function, add an event instead.
Sep 12 '08 #19
Once again, sorry for taking so long to reply, but thank you for all of your help, it is working perfectly now. :)
Oct 3 '08 #20
acoder
16,027 Expert Mod 8TB
No problem. At least it's working and it's better late than never ;)
Oct 4 '08 #21

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

Similar topics

6
by: R. Rajesh Jeba Anbiah | last post by:
In IE, I could be able to directly refer the "id", but it isn't possible in Firefox. Somewhere I read the solution is to refer the id like document.getElementById("month") in Firefox. If I do so,...
5
by: LRW | last post by:
(Sorry if this is a repost...my newsreader keeps crashing on the posting--I don't know if the message going out or not) For some reason this javascript just won't work in Firefox. It works fine...
1
by: Mickey | last post by:
Hi, I have a script which works in both IE but is sluggish in Firefox. The script is a simple text scroller. It works perfectly in IE however in Firefox, the text scroll slower and eventually...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
2
by: AndrewW | last post by:
Hi I have an application that draws a selection rectangle over a map image. I can get it to work fine in IE and Opera, but not Firefox/Netscape. I've thrown the following small example...
2
by: Noah Sussman | last post by:
Hello, I am writing a function to reposition an element based on whether one of its edges is outside the visible area of the browser window (the code is below). My client has asked for code...
4
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the...
2
by: reynoldlariza | last post by:
Can somebody please help me, i tried playing around with IE6 and Firefox 2.0 browser for setting zIndexes and hide & show of divs. It seems to work to both. I tried repeatedly clicking on different...
3
by: visu | last post by:
Hi , I need a solution for my problem with IFRAME in firefox. The problem is that i ve to make the IFRAME to increase in its height to displays its whole content dynamically .i ve set...
6
by: MZ | last post by:
Hello! The following js code doesn`t work fine on Firefox and I don`t know why. I have table with 30 rows and on IE I click once on analyse button and it fills my cells automaticaly, but when I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.