Jump to content

Help a Newbie?


knuckledog
 Share

Recommended Posts

I have script that is going to be employed on a glossary page. The idea is that the user clicks on a Japanese word (within a scrolldown list) and underneath the word appears the English translation. The script at the moment reads as follows (in the header):

<script language="javascript"> <!-- var state = 'none'; function showhide(layer_ref) { if (state == 'block') { state = 'none'; } else { state = 'block'; } if (document.all) { //IS IE 4 or 5 (or 6 beta) eval( "document.all." + layer_ref + ".style.display = state"); } if (document.layers) { //IS NETSCAPE 4 or below document.layers[layer_ref].display = state; } if (document.getElementById &&!document.all) { hza = document.getElementById(layer_ref); hza.style.display = state; } } //--> </script> 

The script in the body reads like this

<p><a href="#" onclick="showhide('div1');">show/hide me</a></p> <div id="div1" style="display: none;">This is the content</div><p><a href="#" onclick="showhide('div2');">show/hide me</a></p> <div id="div2" style="display: none;">This is the content</div>

It actually works after a fashion but I have one major problem. The problem is that once you click on one term (one highlighted word) all the terms change color (as if the user has opened and closed them all). If somebody could offer me some feedback on how to correct this problem (please explain things easily because I am not that Javascript literate), I would greatly appreciate it. RegardsKnuckle

Link to comment
Share on other sites

That's because the URL "#" is now in the user's history list and all the links are pointing to it.I'm not sure if it will be effective, but try this:<p><a href="javascript: void(0)" onclick="showhide('div1');">show/hide me</a></p><div id="div1" style="display: none;">This is the content</div><p><a href="javascript: void(0)" onclick="showhide('div2');">show/hide me</a></p><div id="div2" style="display: none;">This is the content</div>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...