Results 1 to 2 of 2

Thread: javascript onclick button changes css cookie to remember user preference

  1. #1
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile javascript onclick button changes css cookie to remember user preference

    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>

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Hiya,
    This website about creating cookies may help ou. The idea would be to create a cookie remembering th style selection.
    Bernie

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •