View Full Version : please help to modify cookie

08-08-2006, 04:32 PM
please help to modify cookie

Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/switchmenu.htm

hello everyone... i really need someone to modify this for me...
cookie that i have there remembers which menu block the user is using.
what i am trying to fix is:
- when user clicks on any link within the block i want that link to be highlighted and stay highlighted after page refresh and then have white background if other link is in use. So basically only active link to be highlighted and stay highlighted for user to see where he is....
any help will be appreciated.. thank you

my code:

<script type="text/javascript">

var persistmenu="yes"
var persisttype="sitewide"

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
function SwitchMenu(obj){
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("ol");
if(el.style.display != "block"){
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu"){
ar[i].style.display = "none";
el.style.display = "block";

function get_cookie(Name){
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0){
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
return returnvalue;

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)

if (persistmenu=="yes" && document.getElementById)


i thought of using this function for highlightnig:

function highlight(which,color) {
var rows=document.getElementsByTagName("li");
for(i=0;i<rows.length;i++) {

and here is the piece of my HTML menu

<div id="masterdiv">
<table width="100%">
<td class="title"><b>Home:</b><a href="javascript: void(0);" onclick="sub1.style.display='none';" style="text-decoration: none">&nbsp;[-]</a><a href="javascript: void(0);" onclick="SwitchMenu('sub1')" style="text-decoration: none">[+]</a></td></tr></table>
<cfoutput><table width="100%">
<cfset lnk_path = "#application.projectDir#/tools/training/web/test_index.cfm?">
<tr valign="top">
<ol class="submenu" id="sub1">
<li><a href="#lnk_path#fuse=home_welcome" onclick="highlight(this);">Welcome</a><br>
<li><a href="#lnk_path#fuse=home_overview" onclick="highlight(this);">Overview</a><br>
<li><a href="#lnk_path#fuse=home_mission" onclick="highlight(this);">Mission</a><br>
<li><a href="#lnk_path#fuse=home_prerequisites" onclick="highlight(this);">Prerequisites</a><br>
<li><a href="#lnk_path#fuse=courses" onclick="highlight(this);">Computer Based Training</a>

so basically the onload and save functions should be changed...... thank you