Jump to content

need help


phpnoob

Recommended Posts

Hi I have a game list, and in left side in page, have a year-month archive, i have a js code, but it have a little problem, when i click the first and then the second year, then the first year not closed it.

<script type="text/javascript">function drop(open){if (document.getElementById(open).style.display == "none"){document.getElementById(open).style.display = "block";}else{document.getElementById(open).style.display = "none";}}</script>   <span onclick="drop('archive') " style="cursor: pointer; font-weight: bold;text-decoration: underline; color: red; font-size: 18px;"><div id="archive" style="display: none; text-align: left; text-decoration: underline; font-weight: bold;"> 

Thx for the help

Link to comment
Share on other sites

IF what you posted is the exact code, you are missing the span and div closing tags: </span> </div>However, I'm not sure if that was the problem because there could be more to your code that you haven't posted but if all is well, it should work like below:

<!doctype html><html><head><title>phpnoob</title><script type="text/javascript">function drop(open){if (document.getElementById(open).style.display == "none"){  document.getElementById(open).style.display = "block";}else{  document.getElementById(open).style.display = "none";}}</script></head><body><span onclick="drop('archive') " style="cursor: pointer; font-weight: bold;text-decoration: underline; color: red; font-size: 18px;">Hello</span><div id="archive" style="display: none; text-align: left; text-decoration: underline; font-weight: bold;">hello there</div></body></html>

Link to comment
Share on other sites

All your function is doing is telling only one element to open or close (the element you are passing into the function as 'open'). If you are trying to toggle between two elements being opened and closed, then you have to tell the other element to close when one you want opened, is opened. JS will not assume any functionality for you, you have to write the code to do exactly what you want it to do. Also, if you haven't heard of CSS, I would highly encourage you use it.http://www.w3schools.com/css/default.asp

Link to comment
Share on other sites

IF what you posted is the exact code, you are missing the span and div closing tags: </span> </div> However, I'm not sure if that was the problem because there could be more to your code that you haven't posted but if all is well, it should work like below:
yes that the problem, i'm not good in js. need help. thescientist: what do you mean? i'm not sure it can make a css drop down menu.
Link to comment
Share on other sites

which part of what I said? Do you understand why it's not working? I tried to explain that to you. I suggested CSS because all your styles are inline now, which is a bad practice. Have you googled CSS dropdown menus? Or even JS dropdown menus?

Link to comment
Share on other sites

which part of what I said? Do you understand why it's not working? I tried to explain that to you. I suggested CSS because all your styles are inline now, which is a bad practice. Have you googled CSS dropdown menus? Or even JS dropdown menus?
yes i was search it, but i dont find a right 1, i find only touch drop down menu, no click 1 only in js.but ok i try to search it again
Link to comment
Share on other sites

CSS - http://www.cssplay.co.uk/JS - http://vandelaydesign.com/blog/tools/dropdown-navigation-menus/ CSS is a better way to go depending on the complexity of the navigation. If you plan on using JS, you should now the basic of JS first. Like understanding why your original script only ever shows or hides one element, for example, as opposed to toggling like you expected it to.

Link to comment
Share on other sites

thx for helping, btw i find a good 1.

function clickMenu(menu) {var getEls = document.getElementById(menu).getElementsByTagName("LI");var getAgn = getEls;for (var i=0; i<getEls.length; i++) {   getEls[i].onclick=function() {    for (var x=0; x<getAgn.length; x++) {    getAgn[x].className=getAgn[x].className.replace("unclick", "");    getAgn[x].className=getAgn[x].className.replace("click", "unclick");    }   if ((this.className.indexOf('unclick'))!=-1) {    this.className=this.className.replace("unclick", "");;    }    else {    this.className+=" click";    }   }  }}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...