如何保存输入类型“颜色”

Im working at a profile page and want to add a 'favorite color' button. So this is the code I used in my view:

<span class="form-label">Your favorite color:</span>
<input id="my_color" type="color"/>`<span class="form-label">

So on the profile page the 'color picker' is visible.

This is the save function in my javascript. (it works for the other profile options.

var saveChanges = function ()
{
    var jsonData = {};

    $('#user_info input').each(function () {
        var key = $(this).attr('id');
        var value = $(this).val();
        jsonData[key] = value;
    });

I can save the color I picked and if I look it up in my database (my_color) I see the hex color code I picked so that is working. But after I save my profile and I refresh the page you still see the default (black) color and not the color I picked before saving.

Can someone help me to show the color on the profile page.

Thanks

I guess is can happen because of two reasons:

  1. You forgot to set the data while you generate the page using your php code. You need something like: <input type="color" id="theId" value="#<some php code to get the value>" />
  2. You missed the "#". "#220056" gives a color, but "220056" gives Black.

Hope it helps, Regards

Im sorry guys I made a mistake. In my databse column I limited the characters to 6. I forgot # is also a character so I had to do char(7) Now it works! Still thanks for your help and answers.