0

I want to set a cookie to listen to a checkbox (true/false) so it will change the state of the cookie below the code in the page where I set the cookie

  $(document).ready(function ()
     {

         $('#ContentPlaceHolder1_chkSD').change(function setCookie() {
             if ($('#ContentPlaceHolder1_chkSD').is('checked')) {

                 document.cookie(setCookie, true);

                 // console.log('cooooooookie = true');
             }
             else {
                 // console.log('kooouuuuuukiiiie = false');
                 document.cookie(setCookie, false);
             }


         })

         function setCookie(c_name, value, exdays) {
             var exdate = new Date();
             exdate.setDate(exdate.getDate() + exdays);
             var c_value = escape(value) +
               ((exdays == null) ? "" : ("; expires=" + exdate.toUTCString()));
             document.cookie = c_name + "=" + c_value;
         }

This does not work, I get 0x800a138a - JavaScript runtime error: Function expected once I click on the checkbox

1 Answer 1

1

Make sure you are correctly calling your setCookie function by passing it the expected parameters (cookie name, value and expires):

if ($('#ContentPlaceHolder1_chkSD').is('checked')) {
    setCookie("cookie_name", "true", null);
} else {
    setCookie("cookie_name", "false", null);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.