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.

How do You Save Data When Switching Pages?

View previous topic View next topic Go down

Solved How do You Save Data When Switching Pages?

Post by Draxion on August 21st 2017, 10:59 pm

Technical Details


Forum version : #phpBB3
Position : Founder
Concerned browser(s) : Google Chrome
Screenshot of problem : https://i.gyazo.com/86ef89ce863bb6a0df5b63c5f788124d.gif
Who the problem concerns : All members
Forum link : ( link is hidden, you must reply to see )

Description of problem

This is more of a question or solution to my problem. I may know about coding but JavaScript and Jquery are where I am still learning more about and saving data on servers ain't one of them. As you can see in the screenshot, members can switch between CSS styles to make the forum a dark or light theme. I noticed when I changed it to the light theme, I had to do it again every time the pages reloads or switching between pages in the forum. Is there a way I can have it to where it saves the data they chose?

JavaScript:
Code:
$(document).ready(function() {
  $("#myonoffswitch").change(function() {
    $("body").toggleClass("light-mode");
    $("#wrap").toggleClass("light-mode");
  });
});

Thanks for your help!


Last edited by Draxion on August 24th 2017, 12:18 am; edited 1 time in total
avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by SLGray on August 22nd 2017, 1:48 am

You need a line of code that saves cookies. Are you using the one by Ange Tuteur?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 40209
Reputation : 2716
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Draxion on August 22nd 2017, 3:35 am

No, it's my own that I found online how to do and styled myself.

Yes, but I don't know how to code it to save cookies.


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Draxion on August 23rd 2017, 5:51 pm

bump


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Draxion on August 24th 2017, 6:37 pm

Bump


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Justice™ on August 24th 2017, 9:13 pm

Hello,

There are ways to do this on a fm forum:using localStorage or using cookies. I don't recommend you to use cookies since you are a beginner and localStorage is easier to use. The code would look like this:
Code:
$(function(){ /*Wait for the page to load*/
var light=0; /*By default we have the dark theme*/
if(localStorage.getItem("light")!=null){ /*If the localStorage item exists*/
$("body, #wrap").toggleClass("light-mode"); /* toggle the class(actually adding it since it doesn't exist at first*/
light=1; /*Remember we have the light theme*/
};
$("#myonoffswitch").click(function(){ /*When the user clicks on the element*/
if(light){ /*If the light theme is active*/
light=0; /*Remember we now have the dark theme*/
localStorage.removeItem("light"); /*Remove the localStorage item*/
} else { /*Otherwise, we have the dark theme*/
light=1; /*Remember we now have the light theme*/
localStorage.setItem("light", "light")
}
$("body, #wrap").toggleClass("light-mode"); /*Toggle the class*/
});
})

Note:I haven't tested the code. Also, the change event(second line in your code) can only be used on input elements. As you can see in my code I'm using the click event. It should work the same(theoretically better), but if the code is not working, change
Code:
click
to
Code:
change
in my code.
avatar
Justice™
Forumember

Posts : 514
Reputation : 117
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Draxion on August 24th 2017, 9:18 pm

Thank you so much, @Justice! That worked like a charm and I appreciate you explaining in every detail of how it works. Quick question though, is there a way to save the switch styles in the cookies too?

As you can see, the CSS styles were changed and saved as cookies, but the switch was reset back when I refreshed the page.


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Justice™ on August 24th 2017, 9:25 pm

Yes it's possible. When you click on the button you add a class/id to it or how do you modify it's style?
avatar
Justice™
Forumember

Posts : 514
Reputation : 117
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Draxion on August 24th 2017, 9:28 pm

This is how the button is changed when clicked on.
Code:
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  margin-left: 0;
  width: 215%;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
  right: 0px;
  background-color: #000;
}


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Solved Re: How do You Save Data When Switching Pages?

Post by Draxion on August 24th 2017, 9:57 pm

Never mind, Thank you @Justice! I did it myself thanks to your directions.

Again, thank you!
Problem solved & topic archived.
Please read our forum rules: ESF General Rules


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1713
Reputation : 223
Language : English
Location : USA

http://www.draxionsgameden.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