• 0

javascript help!


Question

i'm trying to create a nested menu...where, when the user clicks on the link is provided with subcategories of links which are displayed in a different frame. the problem is that, it works...but not correctly. when i load the page, and click on the link, it does nothing (may load a new page), after that when i refresh the page, then it shows the subcategories...same thing when i'm trying close the nested links. i click on it - nothing. i refresh. it works..

can anyone tell me why this might be?...i'm guessing the cookies are not being read at the right time. but not sure how to fix it.

....
....
<head>
...
...
// object constructor for each outline entry
	function dbRecord(mother, display, URL, indent, statusMsg)
	{ this.mother = mother; ?	// is this item a parent?
 ? this.display = display; ?// text to display
 ? this.URL = URL; ? ?// URL if it exists (link that belongs to the text)
 ? this.indent = indent; ?	// how deeply nested?
 ? this.statusMsg = statusMsg;	// descriptive message on status bar.
 ? 
 ? return this;
	}

// preload images to cache
	var fillerImg = new Image(1, 1);
	fillerImg.src = "..\Images\filler.gif";

// ** functions that get and set persistent cookie data **
// set cookie data
	var mycookie = document.cookie;

	function setCurrState(setting)
	{ mycookie = document.cookie = "currState=" + escape(setting);
	}

// retrieve cookie data
	function getCurrState()
	{ var label = "currState=";
 ? var labelLen = label.length;
 ? var cLen = mycookie.length;
 ? var i = 0;
 ?
 ? while (i < cLen)
 ? {	var j = i + labelLen;
 ? ? if (mycookie.substring(i, j) == label)
 ?{ var cEnd = mycookie.indexOf(";", j);
 ? ?if (cEnd == -1)
 ? ?{ cEnd = mycookie.length;
 ? ?}
 ? ?return unescape(mycookie.substring(j, cEnd));
 ?}
 ?i++;
 ? }
 ? return "";
	}

// **function that updates persistent storage of state**
// toggles an outline mother entry, storing new value in the cookie
	function toggle(n)
	{ var newString = "";
 ? var currState = getCurrState();
 ? var expanded = currState.charAt(n); ? ? ?	// of clicked item
 ? 
 ? newString += currState.substring(0, n);
 ? newString += expanded ^ 1; ? ? ? ?	// Bitwise XOR clicked item
 ? newString += currState.substring(n + 1, currState.length);
 ? setCurrState(newString); ? ? ? ? ?// write new state back to cookie
	}

// setting the message on the status bar
	function getGIFStatus(n, currState)
	{ var mom = db[n].mother;	//is the object a mother?
 ? var expanded = currState.charAt(n);
 ? 
 ? if (!mom)
 ? { return "No further collapsed items.";
 ? }
 ? else
 ? { if (expanded == 1)
 ? ?{ return "Click to collapse the nested items.";
 ?}
 ? }
 ? return "Click to expand nested items.";
	}

	if (getCurrState() == "" || getCurrState().length != (db.length))
	{ var initState = "";
 ? for (i = 0; i < db.length; i++)
 ? { initState += "0";
 ? }
 ? setCurrState(initState);
	}
// end -->

 ?</script>
 </head>

 <body class="menulink">
 ?<script language="javascript" type="text/javascript">
<!-- start
// build new outline based on the values of the cookie
// and data points in the outline data array.
// This fires each time the user clicks on a control,
// because the HREF for each one reloads the current document.
	var newOutline = "";
	var prevIndentDisplayed = 0;
	var showMyDaughter = 0;
	var currState = getCurrState(); // get whole state string

	for (var i = 0; i < db.length; i++)
	{ //var theGIF = getGIF(i, currState) // get the image
 ? var theGIFStatus = getGIFStatus(i, currState) // get the status message
 ? var currIndent = db[i].indent // get the indent level
 ? var expanded = currState.charAt(i) // current state
// display entry only if it meets one of three criteria
 ? if (currIndent == 0 || currIndent <= prevIndentDisplayed || (showMyDaughter == 1 && (currIndent - prevIndentDisplayed == 1))) {
 ? ?newOutline += "<IMG SRC=..\"filler.gif\" HEIGHT = 1 WIDTH =" + (indentPixels * currIndent) + ">";

 ? ?newOutline += "<A HREF=\"javascript:history.go(0)\" " + "onMouseOver=\"window.status=\'" + theGIFStatus + "\" + onClick=\"toggle(" + i + ");" + "\"></A>";

 ? ?newOutline += "<A HREF=\"" + db[i].URL + "\" + TARGET=\"" + displayTarget + "\" + onMouseOver=\"window.status=\'" + db[i].statusMsg + "\" + onClick=\"toggle(" + i + ");" + "\">" + db[i].display + "</A><BR>";
 ? ? ?
 ? ? ?prevIndentDisplayed = currIndent;
 ? ? ?showMyDaughter = expanded;
 ? ?}
	}
	document.write(newOutline);
 ?-->
 </script>
 </body>
</html>

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.