How to Write A Cookie In JavaScript to Make an Attribute Appear

I am new to web development, and I am having some trouble writing to a cookie using javascript from within HTML. I am attempting to make a division tag and its elements appear if the value of the cookie's view property are set to true. Once the close option is clicked, the cookie changes the value to false and should not allow a user to be able to view the elements within the division tag again. I have spent the past 8 hours trying to use the attached code, with no luck. Any help would be greatly appreciated.)
function setCookie2(c_name, value, exdays) {
            var exdate = new Date();
            var PolicyNum = "<%=strPolicyNumber%>";
            exdate.setDate(exdate.getDate() + exdays);
            var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
            document.cookie = "Policy=" + PolicyNum + "; " + c_name + "=" + c_value;
        }

        function getCookie2() {
            var c_name = "DontShowMsg";
            var i, x, y, ARRcookies = document.cookie.split(";");
            var PolicyNum = "<%=strPolicyNumber%>";
            for (i = 0; i < ARRcookies.length; i++) {
                x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
                y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
                x = x.replace(/^\s+|\s+$/g, "");

                if (x == "Policy" && y == PolicyNum) {
                    //hide_msg();
                }
                else {
                    alert(x + y);
                    show_msg();
                }

            }
        }

        function perm_close(){
            hide_msg();
            setCookie2("DontShowMsg", "Yes", "365");

        }
        
        function hide_msg() {
            document.getElementById("warnings").style.display = "none";
        }

        function show_msg() {
            document.getElementById("warnings").style.display = "block";

        }

Open in new window

thenthorn1010Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

COBOLdinosaurCommented:
Do you realize that the user will still be able to see the contents of the div by viewing source, and that they must allow cookies. and that you should be handling this server side by simple not writing the information if the user has previously seen it.


Cd&

0
COBOLdinosaurCommented:
Are you sure this value is being written correctly to the client?

I don't see the link, and you have not posted client side code so there is no way for me to check it myself.

Cd&
0
thenthorn1010Author Commented:
COBOLdinosaur,

I apologize for forgetting to attach the remaining code. Attached is the code. Let me know if you have any questions. THanks again for the help.

<div id="warnings">
                <div id="warningMess">
                                <h2>Click here for an important notice about Quicken Health Expense Tracker</h2>
                </div>
    <div id="warningClose">
                <h3>Don’t show this again</h3>
    </div>
    <div id="warningCloseBt">
                <img src="../MHP/WarningCloseButton.png" />
    </div>
</div>

Open in new window

#warnings {
                -moz-border-radius:10px;
    -webkit-border-radius:10px;
    border-radius:10px;
    border: 1px #ff686b solid;                            
    background: -moz-linear-gradient(19% 75% 90deg, #f87273, #feb4b5);
    background: -webkit-gradient(linear, left top, left bottom, from(#f87273), to(#feb4b5));
                background: -ms-linear-gradient(top, #ffb6b6, #fb8b8b);
                background: -o-linear-gradient(top, #ffb6b6, #fb8b8b);
    background-color: #fb9899;
                width:718px;
                height:34px;
                margin:0 0 0 19px;
}

#warnings h2{
                font-family:Verdana, Geneva, sans-serif;
                font-size:12px;
                text-decoration:underline;
                padding:10px;
                margin:0;
}

#warnings h3{
                font-family:Verdana, Geneva, sans-serif;
                font-size:11px;
                font-weight:normal;
                text-decoration:underline;
                padding:10px 0 10px 10px;
                margin:0;
}

#warningMess{
                float:left;
                width:555px;
} 

#warningClose {
                float:left;
                position:relative;
}

#warningCloseBt {
                float:right;
                position:relative;
                padding:10px 10px 10px 3px;
}

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

COBOLdinosaurCommented:
I'm missing a connection here somewhere how and where are the functions being called? I see showmsg and hide masg in the get cookie function, but I don't see a call to the cookie functions, or any event fired from a click.


Cd&
0
thenthorn1010Author Commented:
COBOLdinosaur,

Attached is the code updated with the updated code for how I intend for the events to be called when a link is clicked on in the banner, along with the "Click here to close" and the "X" image. The banner is supposed to not display for users ever again, unless they clear their cookies, if the user clicks on "Click here to close" or the "X" image. (I was trying to attempt to do this using a cookie. The cookie has to be written as a unique value each time a different user on the users computer were to click on it because more than one user is "capable" of using their account and clicking on the event-driving actions.)

I hope the updated code and this explanation clears up any confusion. Thank you again for any help you can provide.  
<div id="warnings" style="display:none;">
                <div id="warningMess">
                   <h2><a href="javascript:showpopup()">Click here for an important notice about Quicken Health Expense Tracker</a></h2>
                </div>
                <div id="warningClose">
                    <h3><a href ="javascript:perm_close()">Don’t show this again</a></h3>
                </div>
                <div id="warningCloseBt">
                    <img src="/imm/WarningCloseButton.png" onclick="javascript:perm_close()" />
                </div>
            </div>

Open in new window

0
COBOLdinosaurCommented:
The way that code is written looks like the whole thing including the link that is supposed to get clicked is hidden.

The link has to be outside of the div and be hidden separately.


Cd&



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.