The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

javascript with cookeis

View previous topic View next topic Go down

In progress javascript with cookeis

Post by H.A.SS.A.N on August 18th 2015, 8:04 pm

hello , anybody tell me how I can save changes in javascript by cookeis
for example
this code in tamplate
Code:

$("#div1").click(function() {
        $("#div2").hide();
    });

when I click on div1 the div2 hide , ok I need this effect presist for long time .
not return to first value on refreshing the page

please I need this manner quickly
THANK YOU


H.A.SS.A.N
Forumember

Posts : 77
Reputation : 1
Language : Arabic

http://www.deve-net.com

Back to top Go down

In progress Re: javascript with cookeis

Post by Ange Tuteur on August 18th 2015, 8:32 pm

Forumotion has the following functions installed on the forums for handling cookies.

my_setcookie : sets a cookie. For example :
Code:
my_setcookie('cookieName', 'cookie value');

my_getcookie : gets an exisiting cookie and returns its value if it has one. For example :
Code:
my_getcookie('cookieName'); // returns 'cookie value'

This is a simple example :
Code:
$(function() {
  var div = document.createElement('DIV'), button = document.createElement('INPUT'), cookie = my_getcookie('divState');
  div.innerHTML = 'Hello';
  div.id = 'containingElement'
  if (cookie == 'hidden') div.style.display = 'none';
 
  button.type = 'button';
  button.value = 'Toggle';
  button.onclick = function() {
    var div = document.getElementById('containingElement');
   
    if (/none/.test(div.style.display)) {
      div.style.display = '';
      my_setcookie('divState', 'shown');
    } else {
      div.style.display = 'none';
      my_setcookie('divState', 'hidden');
    }
  };
 
  document.body.appendChild(div);
  document.body.appendChild(button);
});

The script creates two elements and appends them to the body; a button and container. The button toggles the display state of the container, and the cookies handle the state whenever the page is changed.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: javascript with cookeis

Post by H.A.SS.A.N on August 18th 2015, 9:44 pm

I'm stupid hhhhhhhhhhh , I'm not fully understand this manner ??
I have botton when I click it lead to make the display value of some elements is 'none'
I neesd to save it and
also for checkbox when is cheched or not
can you make example in html page
THANK YOU

H.A.SS.A.N
Forumember

Posts : 77
Reputation : 1
Language : Arabic

http://www.deve-net.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum