Log in

View Full Version : javascript onclick button changes css cookie to remember user preference



testing123
06-25-2012, 11:35 AM
Hi

I am really new to Java Scripting so any help would be great. I have been googling for days and I have seen a number examples on how people do what I am trying to do but I don't understand their code. I am trying to provide my user with accessibility buttons so they can change the font size of the text or change the background colour and text colour.

I have a number of sytle sheets which my visitors can than select through Javascript buttons. This works fine

I would like to then use a cookie to remember the users preference when they change to another page on my site but I just cant get it to work

the code I have which works for changing between style sheets is below, could anyone help with code which will work to remember what a user has selected on the next page?

<link href="style2.css" type="text/css" rel="stylesheet" id="stylesheet" />
<script language="javascript">
<!--
function changeStyle(name){
if(name=='style1')
document.getElementById('stylesheet').href='style1.css';
else if(name=='style2')
document.getElementById('stylesheet').href='style2.css';
else if(name=='style3')
document.getElementById('stylesheet').href='style3.css';}



<td width="22"><input type="button" name="SmallA" class="SmallA" value="A" title="Small Font Size" onclick="changeStyle('style1')"></td>
<td width="24"><input type="button" name="MediumA" class="MediumA" value="A" title="Medium Font Size" onclick="changeStyle('style2')"></td>
<td width="26"><input type="button" name="LargeA" class="largeA" value="A" title="Large Font Size" onclick="changeStyle('style3')"></td>

bernie1227
06-25-2012, 10:50 PM
Hiya,
This (http://http://www.quirksmode.org/js/cookies.html) website about creating cookies may help ou. The idea would be to create a cookie remembering th style selection.
Bernie