Jump to content

javascript code


Spunky

Recommended Posts

Ok if you go to this page notice first that in the url after it shows '?panelToOpen=mandelbrot'. Now, notice at the bottom there are 4 different titles and an arrow for each. Each of these arrows currently are facing down. They should all be facing to the right, except for the currently opened panel(mandelbrot), like they do properly when the code that is acting funny isn't being used, like if you take out '?panelToOpen=mandelbrot' part.For the sake of pasting repetative code I will only paste all the code up to the first panel, because each panel after that is identical. Here is the code being used to make the buttons work properly and the panels open and close. The code works just fine, exactly how I want it to, I am just posting it incase it is of importance and so you can see what exactly is happening:

$(document).ready(function(){$("p#mandelbrotPanel").hide();$("p#matchPanel").hide();$("p#thePassagePanel").hide();$("p#towerSiegePanel").hide();$("div#fourthTitle").css("border-bottom","2px solid #000");$("p#towerSiegePanel").css("border-bottom","2px solid #000"); $("img#firstTitleButton").click(function(){	document.getElementById("firstTitleButton").src = "images/arrowButtonActive.png";	$("p#mandelbrotPanel").slideToggle("slow", function(){  if($("p#mandelbrotPanel").is(":hidden")){   document.getElementById("firstTitleButton").src = "images/arrowButton.png";  }; });  });//other panel's code is here, but is exactly the same.});function mouseOver(whichButton,whichPanel) {if($("p#"+whichPanel).is(":hidden")){  document.getElementById(whichButton).src="images/arrowButtonActive.png"; } else if($("p#"+whichPanel).is(":visible")){  document.getElementById(whichButton).src="images/arrowButton.png"; }}function mouseOut(whichButton,whichPanel) { if($("p#"+whichPanel).is(":visible")){  document.getElementById(whichButton).src="images/arrowButtonActive.png"; } else if($("p#"+whichPanel).is(":hidden")){  document.getElementById(whichButton).src="images/arrowButton.png"; }}

Now, the code being implemented when a link is clicked that I want to cause a panel to automatically being opened when I go to the page is this. This is the code that when implemented is causing all the arrows to face down, even though the panels are closed:

$(document).ready(function(){	urlExtract = location.search	foundExtract = urlExtract.split("=")[1];	$("p#" + foundExtract + "Panel").slideToggle("slow");	if(foundExtract="mandelbrot"){		document.getElementById('firstTitleButton').src="images/arrowButtonActive.png";	}		//again, the other panel's code is here, but is exactly the same})

Looking at this, you know the 'foundExtract' variable is being read correctly because the correct panel is being opened, you can even test that by putting in a different title in the url (?panelToOpen=match), each of them will work just the same. Just for some reason the if statement is not working and I cannot figure out why. And just to be clear if I take out the if statement for one of the panels, including the one that is opened at the start, the arrows do face to the right, so what is happening here is each of the if statements for all four panels are working, despite we know that "foundExtract" can only mean the correct panel as it is being used to open the correct one.The reason I am not giving the link that actually links to this page and causes the url to have the 'panelToOpen' part is because this page isn't live yet for viewers, there is no link to it anywhere on the rest of the website.Maybe I am missing something small I dont know, I just cant figure out for the life of me why the if statements are all automatically true or whatever.

Link to comment
Share on other sites

Ok. I dont have an answer but the link to your page isnt on the web, its from you hard disk. :) Good Luck with finding your answer!
oops my bad. I had them both open cuz I test locally and then I put it so you guys can see.click here instead.
Link to comment
Share on other sites

if(foundExtract="mandelbrot"){  document.getElementById('firstTitleButton').src="images/arrowButtonActive.png";}

when testing for value's, you need to use == or ===.http://www.w3schools.com/js/js_comparisons.asp

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...