PDA

View Full Version : Cookie, help



Nate_Bro
10-11-2004, 05:56 PM
Ok, i'm just starting to learn cookies, so i was wondering is someone could help, I made this page, and i would like it to remember the settings so evry time it is loaded, it has the same settings as before, thanks, ~Nate_Bro

i kinda got lost, so i just stoped, before i got confused to badly :confused:



<HTML>
<HEAD>

<style type="text/css">
.texta {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
font-weight: bold;
background: #000000;
padding: 1px;
border: 2px solid #CCCCCC;
}
</style>

<SCRIPT>

function set(){

document.cookie="link="+document.form.link.value
document.cookie="alink="+document.form.alink.value
document.cookie="vlink="+document.form.vlink.value
document.cookie="fgcol="+document.form.fgcol.value
document.cookie="bgcol="+document.form.bgcol.value
document.cookie="bgpic="+document.form.bgpic.value
}

function getCookie(name){

var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}

function use(){

ver alink = (getCookie("alink"))
ver link = (getCookie("link"))
ver vlink = (getCookie("vlink"))
ver bgcol = (getCookie("bgcol"))
ver fgcol = (getCookie("fgcol"))
ver bgpic = (getCookie("bgpic"))

document.form.alink.value = alink
document.form.link.value = link
document.form.vlink.value = vlink
document.form.bgcol.value = bgcol
document.form.fgcol.value = fgcol
document.form.bgpic.value = bgpic
}

function chng(){

document.bgColor = document.form.bgcol.value
document.fgColor = document.form.fgcol.value
document.linkColor = document.form.link.value
document.vlinkColor = document.form.vlink.value
document.alinkColor = document.form.alink.value
document.body.background = document.form.bgpic.value
}
</SCRIPT>

</HEAD>

<BODY onload="use(),chng()">

<FORM name="form">
<p></p><INPUT type="text" class="texta" length=20 name="link">
<p></p><INPUT type="text" class="texta" length=20 name="alink">
<p></p><INPUT type="text" class="texta" length=20 name="bgpic">
<p></p><INPUT type="text" class="texta" length=20 name="bgcol">
<p></p><INPUT type="text" class="texta" length=20 name="vlink">
<p></p><INPUT type="text" class="texta" length=20 name="fgcol">

<P>
<INPUT type="button" value="Save" name="none" onClick='set()'>
<INPUT type="button" value="Show" name="none2" onClick='chng()'>
</FORM>

</BODY>
</HTML>

Nate_Bro
10-11-2004, 11:40 PM
ok, i updated it, i had it working at one point, thanks again ~Nate_Bro