We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    Hi,

    For a MODx site, I need a panel of checkboxes which state is kept from one page to another.
    To do things simply, I planned to use cookies, one per checkbox.
    I’m not so familiar with jQuery and code below is wrong. Can some experienced jQuery coder help a little bit ?
    <script type="text/javascript" langage="Javascript">
         $(document).ready(function(){
           $("div.chkInfo input[@type=checkbox]").each(checked=LireCookie(val));
         }); 
    </script>

    The details :
    - Each checkbox to select is in a div having class chkInfo
    - Each cookie to read has for name the value of its checkbox.
    - The LireCookie() function returns the value (true|false) of a cookie from its name passed as argument.
    (The code of the function is here http://www.actulab.com/lire-les-cookies.php)
    - The cookies were written with function EcrireCookie() (http://www.actulab.com/ecrire-les-cookies.php)
      • 33372
      • 1,611 Posts
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 15001
        • 697 Posts
        Thanks. I read the tutorial from the first url and also had a look at the second ressource.
        However, for my simple case, I decided to do without the ressource from texotela.

        I improved my code, but for the function that handles the click() event, there is some strange thing : the condition (this.checked) is never met, even if I replace this.checked=LireCookie(...) by this.checked=true in the initialization block.

        this.checked appears undefined also for the checkboxes that are checked. huh

        Any idea why ? Should I use some other function to test the checked status ?
        Thanks.
        $(document).ready(function(){
        
         // Initialize checkboxes according to the value stored in cookies :
         $("div.chkInfo input[@type='checkbox']").each(function(){
        	 this.checked=LireCookie(this.value);  // LireCookie returns true or null;
         	});
        
          $(this).click(function(){
          	if (this.checked){
        		alert("THIS CASE NEVER OCCURS. WHY ?");
          		date=new Date;
          		date.setMonth(date.getMonth()+1);
          		EcrireCookie(this.value, this.checked, date);
          	} else {
        	  	alert("Erase the cookie");
        	  	EffacerCookie(this.value)	
        	}
          		
          	});
        	
        });