I am trying to save several variables in a cookie and eat, and this is the code:
function changeColors(){
var rd = parseInt(document.getElementById("red").value);
var gr = parseInt(document.getElementById("green").value);
var bl = parseInt(document.getElementById("blue").value);
var op = parseFloat(document.getElementById("opacity").value);
var rdhex = (rd < 16) ? "0" + rd.toString(16) : rd.toString(16);
var grhex = (gr < 16) ? "0" + gr.toString(16) : gr.toString(16);
var blhex = (bl < 16) ? "0" + bl.toString(16) : bl.toString(16);
var hexcode = "#" + rdhex + grhex + blhex;
document.getElementById("div").style.backgroundColor = hexcode;
document.getElementById("colordisplay").innerHTML = hexcode;
document.getElementById("div").style.opacity = op;
}
function WriteCookie()
{
if( document.myform.name.value == "" ){
alert("Enter some value!");
return;
}
cookievalue= escape(document.myform.red.value) + ";" +
escape(document.myform.red.value)+ ";"+
escape(document.myform.green.value)+ ";"+
escape(document.myform.blue.value)+ ";"+
escape(document.myform.opacity.value)+ ";";
document.cookie="color=" + cookievalue;
alert("Setting Cookies : " + "color=" + cookievalue );
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies );
cookiearray = allcookies.split(';');
I need to save the name, RGB and opacity in a cookie so that the user can then choose from the previous colors that he controlled himself. My question is, how can I store the hex code and opacity var with the color name in the cookie?
source
share