Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change styles issue

Status
Not open for further replies.

ruler1

MIS
Feb 19, 2007
89
hi, i found another post on here but lost the url so i cant refer to it but i used their code which works good eccept for one small problem.
the code below allows me to change styles on my pages and saves the selection for the next time i connect to my site however when you first visit there is no default set so you dont get any styles until you actually select one. i was wondering if there was a way to have a default style set for when a user first connects to my pages? here is the code below...

<html>
<head>
<link id="external_style" rel="stylesheet" type="text/css"/>

</head>
<body onLoad="loadStyle()">
<script language="javascript">
var CSS_COOKIE_VAR = "LastCSS";

function changeStyle( oSel )
{ if (sCSS = oSel.value)
{ setStyle( sCSS );
var expires = new Date( 2010, 1, 1 ); // long enough :)
document.cookie = CSS_COOKIE_VAR + "=" + escape( sCSS ) +"; expires=" + expires.toGMTString() + ";" ;
}
}

function setStyle( sCSS )
{ document.getElementById("external_style").href = sCSS;
}

function loadStyle()
{ aCookie = document.cookie.split(";");
for (i=0; i< aCookie.length; i++)
{ aName = aCookie.split("=");
if (aName[0] == CSS_COOKIE_VAR )
{ setStyle( aName[1] );
document.getElementById("control").value = aName[1];
}
}
}
</script>
<form>
<select id="control" name="style" onChange="changeStyle(this)">
<option value="/ <option value="/ <option value="/</select>
</form>
</body>
</html>
 
You need to set an "else" statement in the inital IF on what the browser should do if there is no cookie

--Dan
Whenever you find yourself on the side of the majority, it is time to pause and reflect.
Mark Twain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top