I like adding help messages to web forms, but I find that these help messages can often make the page very long. Since a user won’t like need a help message once he has read it, it’s nice to be able to hide the message.
With that in-mind, the JavaScripts below are nice samples of scripts that will display or hide content that is within a specified <DIV> tag. They can be called from a single button or hyperlink:
function toggleDiv(divName) { thisDiv = document.getElementById(divName); if (thisDiv) { if (thisDiv.style.display == "none") { thisDiv.style.display = "block"; } else { thisDiv.style.display = "none"; } } else { alert("Error: Could not locate div with id: " + divName); }}
function toggleDiv(divName) { var thisDiv = document.getElementById(divName); if (thisDiv) thisDiv.style.display = !thisDiv.offsetWidth ? "block" :"none"; else alert("Error: Could not locate div with id: " + divName);}