2

I have a question about jquery, I want the user to be able to change the color of his/her profile. How could I manage to let the website "remember" that the changes were made?

$(document).ready(function() {
    $('#color2').click(function() {
        $('#color').css("border-color", "#3498db").css("color", "#3498db");
        $('.navbar-default').css("background-color", "#3498db");
    });
});

this is what I have to make the change

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
The_Hobyte
  • 21
  • 1
  • What do you mean by "remember"? Do you mean next time when he loads the page the colors should be the new colors? – Emil Borconi Feb 19 '16 at 22:36
  • 1
    Have you looked at using cookies like shown here: http://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-with-javascript or are you more interested in doing this server side with AJAX? – War Gravy Feb 19 '16 at 22:38
  • You'll want to use a Server language if you have users and you want to store their settings. – StackSlave Feb 19 '16 at 22:39
  • 1
    You could also use [localStorage](https://developer.mozilla.org/en/docs/Web/API/Window/localStorage). – Kenney Feb 19 '16 at 22:40
  • 1
    Server for permanent storage, cookies for temporary. If it's something that should always be remembered, save it on the server, the user can delete cookies whenever. If you're going to do server, you can use AJAX to send the info to the server without forcing the user to leave the page. Look into $.post from jQuery and Google "PHP AJAX jQuery" or replace PHP with your favorite server-side language. You'll find plenty of material there. –  Feb 19 '16 at 22:40
  • Did any answer resolve your issue? If so, please accept it. If not, please tell what else needs to be fixed. – Konrad Viltersten Feb 20 '16 at 11:08

2 Answers2

1

If it's a simple application, you might want to use the local storage of the browser.

localStorage.setItem('color', '#123456');
localStorage.getItem('color');
localStorage.clear();

Note that it's not bound to the users' profiles but scoped to the browser in use. If they go with another browser or use a different machine, the setting isn't known, which can create a weird issue when they jump between settings without understanding why.

In such case, you're better off seding the value picked to the server and storying it there. That requires you to managed it in the server-end code, which might be pulling a nuke to kill a fly.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
0

This could be done via cookie or save it on your database using php not jquery, because jquery is used for user interaction or interface but you can use it to retrieve data using ajax.

netto
  • 135
  • 1
  • 3
  • 11