Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:10:07+00:00 2026-06-09T00:10:07+00:00

I am building this small cookiescript which creates a cookie when clicking on a

  • 0

I am building this small cookiescript which creates a cookie when clicking on a button and then hides the message.

But now I am building the function to hide the message (div#cookie) when the cookie has been seet, but I get this error everytime, but my div DOES exist:

Uncaught TypeError: Cannot read property 'style' of null 

Now these are the scripts I am using, can anyone help? 🙂

<script type="text/javascript">
        function createCookie(name,value,days) {
            if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
            }
            else var expires = "";
            document.cookie = name+"="+value+expires+"; path=/";
        }

        function readCookie(name) {
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
            }
            return null;
        }

        function eraseCookie(name) {
            createCookie(name,"",-1);
        }
        </script>

and this, where-ever the ‘hidediv’ gives the error, but does work when clicking on a button:

<script type="text/javascript">
            function hidediv() { 
                if (document.getElementById) { 
                    document.getElementById('cookie').style.visibility = 'hidden'; 
                    createCookie('uscnCookieScriptJS','uscninternetservicescookiescriptjavascriptversion',365)

                } 
                else { 
                    if (document.layers) { 
                        document.hideShow.visibility = 'hidden'; 
                        createCookie('uscnCookieScriptJS','uscninternetservicescookiescriptjavascriptversion',356)
                    } 
                    else { 
                        document.all.hideShow.style.visibility = 'hidden'; 
                        createCookie('uscnCookieScriptJS','uscninternetservicescookiescriptjavascriptversion',356)
                    } 
                } 
            }

            function showdiv() { 
                if (document.getElementById) { 
                    document.getElementById('cookie').style.visibility = 'visible'; 
                } 
                else { 
                    if (document.layers) { 
                        document.hideShow.visibility = 'visible'; 
                    } 
                    else { 
                        document.all.hideShow.style.visibility = 'visible'; 
                    } 
                } 
            } 
        </script>
        <script type="text/javascript">
        if (document.cookie.indexOf("uscnCookieScriptJS") >= 0) {
          alert("yes");
          hidediv();
        }
        else {
          alert("no");
        }
        </script>

The script can be found here: http://dev.uscn.nl/cookiescript/v2/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:10:08+00:00Added an answer on June 9, 2026 at 12:10 am

    The problem is that you are calling the hidediv() function before loading the actual HTML content. Either put the script in the end of the document (before closing body tag) or set it at window.onload / on document ready

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building this small java applet in which I need a JPanel which will
I'm building this function but I'm not getting the desired output, it's been more
I'm building a small Android application, but this is more of a Java question
I'm building this small desktop application for myself, and until now I've been using
i'm building this little function, what i need is this query to print me
Sorry for such a trivial question, but I'd feel silly building this if it
I am building a small dropdown menu with jQuery, but i am have a
I have this small application that I'm building as an exercise to learn the
I'm building a small Validate object which basically exposes a validate method and takes
So, I'm building this brand-new project in MS Access (2007, but I don't think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.