The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

javascript with cookeis

2 posters

Go down

In progress javascript with cookeis

Post by H.A.SS.A.N 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
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 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
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: javascript with cookeis

Post by H.A.SS.A.N 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
H.A.SS.A.N
Forumember

Posts : 77
Reputation : 1
Language : Arabic

http://www.deve-net.com

Back to top Go down

Back to top

- Similar topics

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