Results 1 to 2 of 2

Thread: Help me to get my cookies working.

  1. #1
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help me to get my cookies working.

    Please someone help me.

    I have created these cookies and want to resize text with two buttons. But I am wrong somewhere and can't think any more. text size is increasing and decreasing. but when I close the page and reopen it the default font is there.I want my preferred font size to be saved as cookies. Please help me.

    thanks

    this is my code..
    Code:
    <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 resizeText(multiplier) {
      
      if (document.body.style.fontSize== ""){
    	  document.body.style.fontSize ="1.0em";
    	  
      }
      
     document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
    }
    
    function setCookie (name) {
    var Cookie
    var resizetext
    resizetext=bodyElement.value;
    createCookie("resizetext",tresizetext, 365);
    return false;
    
    }
    <script>
    HTML Code:
    <lable> This text need to be big and small </label><br />
    <Input type="button"  value= "big text"  onclick="resizeText(1)" />
    <input type="button" value= "Small text"onclick="resizeText(-1)" />
    

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <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 resizeText(multiplier,days){
    
      if (document.body.style.fontSize== ""){
    	  document.body.style.fontSize ="1.0em";
    
      }
    
      document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
      createCookie('body',document.body.style.fontSize,days||-1);
     }
    
    function setCookie() {
     if (readCookie('body')){
      document.body.style.fontSize=readCookie('body')
     }
    }
    </script></head>
    
    <body onload="setCookie();" >
    <lable> This text need to be big and small </label><br />
    <Input type="button"  value= "big text"  onclick="resizeText(1,1)" />
    <input type="button" value= "Small text"onclick="resizeText(-1,1)" />
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •