• 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
https://www.neowin.net/forum/topic/136076-javascript-help/
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.
  • Posts

    • That’s why I love classic Notepad from W10 IOT LTSC. It opens up instantly, uses very little resources, is just a plain notepad and nothing more. the title should be notepad has lost focus.
    • Seeing my profile picture in Notepad creeped me out. I do not appreciate that Copilot is opt-out rather than opt-in. I don't want Notepad to have connectivity. The other improvements are fine, including the upcoming Markdown support (although I hate Markdown's handling of newlines with a passion).
    • More like Trelane: https://memory-alpha.fandom.com/wiki/Trelane But, yes, Q.  
    • This would come in handy to me as an Uber driver. My biggest pet peeve is when passengers listen to their own audio on their phones without using headphones when they can hear I'm already playing music through my car's head unit.
    • Astonishing new tech could kill headphones forever as it bends sound right into ears by Sayan Sen Imagine being able to listen to your favorite song or podcast out loud without disturbing anyone nearby even without wearing headphones. That’s what a team at Penn State University has been working on. Led by acoustics professor Yun Jing, they’ve come up with a clever way to create invisible audio zones called “audible enclaves” where sound can be heard only at one exact spot. They use ultrasound, which is normally inaudible to people, along with something called acoustic metasurfaces—tiny lenses that can bend sound in specific directions. By combining two ultrasound beams that travel in curved paths and meet at a single point, they’re able to make sound audible only at that intersection. As Jing explained, “The person standing at that point can hear sound, while anyone standing nearby would not. This creates a privacy barrier between people for private listening.” To make this happen, the system includes two ultrasonic speakers and the metasurface lenses, which were 3D printed by Xiaoxing Xia from Lawrence Livermore National Lab. Each beam has a slightly different frequency, and when they meet, a local reaction makes the sound audible. Neither beam is loud on its own—the sound only forms at that shared point. Jia-Xin “Jay” Zhong, one of the researchers, shared how they tested the idea: “We used a simulated head and torso dummy with microphones inside its ears to mimic what a human being hears at points along the ultrasonic beam trajectory, as well as a third microphone to scan the area of intersection. We confirmed that sound was not audible except at the point of intersection, which creates what we call an enclave.” One of the biggest advantages of their approach is that it works across a wide range of sound frequencies—between 125 Hz and 4 kHz, which covers most of what people can hears. Even in rooms where sound usually bounces around, their system held up well. And it’s surprisingly compact too: the whole setup measures about 16 centimeters, roughly the size of a pencil case. “We essentially created a virtual headset,” Zhong said. In practice, it means that someone standing in the audible enclave can hear what’s being played clearly, while everyone else around hears nothing at all. That could be especially useful in shared spaces like cars, classrooms, or open offices. Right now, the sound can travel about one meter and hits around 60 decibels which is similar to regular talking volume. The team believes they can push those limits further by using stronger ultrasound. All this might seem futuristic, but it’s grounded in solving a basic problem: how to direct sound only where it’s needed. If you’re into tech and sound design, this could open up a whole new world of personalized audio experiences. Source: Penn State, PNAS | Image via Depositphotos This article was generated with some help from AI and reviewed by an editor. Under Section 107 of the Copyright Act 1976, this material is used for the purpose of news reporting. Fair use is a use permitted by copyright statute that might otherwise be infringing.
  • Recent Achievements

    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
    • Explorer
      cekicen went up a rank
      Explorer
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      211
    3. 3
      Michael Scrip
      197
    4. 4
      Xenon
      149
    5. 5
      +FloatingFatMan
      125
  • Tell a friend

    Love Neowin? Tell a friend!