Hey everyone!
I apologize in advance if this type of thread was already created in the past, but i am totally new to this forum so i decided to start from scratch.
Currently i am working on one of the website that had to be remade so i created an expandable menu on the left side of the page with bunch of submenus, which have links in them. On the right side i have a fuse column which gets updated each time the link is clicked. I wrote a cookie so that when user clicks on some header and then link even after page refresh that submenu block stays open.
What i am trying to accomplish now and i know for a fact it has to do with cookie…. i need to make sure that the link that user clicks on to update page on the rights gets highlighted and stays highlighted after a refresh. If user clicks on other link old link become with white background and new one is highlighted.
here i have my Javascript code, i am sorry i can’t give you full access to website that i am working on because you need special access to it, however, you still can get an idea.
If anyone could please tell me and fix my JS cookie code in order this highlighting would take place properly I would really appreciate it.
i am totally new to web design, therefore i get a lot of trouble with this. ?
thank you
Alina
[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’)
document.write(‘</style>n’)
}
function cal() {
dt = new Date()
mo=dt.getMonth()+1
ts = “http://www.timeanddate.com/calendar/print.html?year=2003&typ=1&display=1&ol=0&space=0&country=1&cols=1&months=1&month=”+mo+”&moon=on&hol=on”
window.open(ts);
}
function calyr() {
dt=new Date()
yr = dt.getYear()
ts = “http://www.timeanddate.com/calendar/print.html?year=”+yr+”&typ=0&display=0&ol=0&space=0&country=1&cols=3&months=12&moon=on&hol=on”
window.open(ts);
}
function SwitchMenu(obj){
if(document.getElementById){
var el = document.getElementById(obj);
var ar = document.getElementById(“masterdiv”).getElementsByTagName(“div”);
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!=””)
document.getElementById(cookievalue).style.display=”block”
}
}
function savemenustate(){
var inc=1, blockid=””
while (document.getElementById(“sub”+inc)){
if (document.getElementById(“sub”+inc).style.display==”block”){
blockid=”sub”+inc
break
}
inc++
}
var cookiename=(persisttype==”sitewide”)? “switchmenu” : window.location.pathname
var cookievalue=(persisttype==”sitewide”)? blockid+”;path=/” : blockid
document.cookie=cookiename+”=”+cookievalue
}
if (window.addEventListener)
window.addEventListener(“load”, onloadfunction, false)
else if (window.attachEvent)
window.attachEvent(“onload”, onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction
if (persistmenu==”yes” && document.getElementById)
window.onunload=savemenustate
</script>