Feedback on: irt.org FAQ Knowledge Base Q984
Comments:
This article has syntax and code errors.
if (toggle = !toggle)
...doesn't look like a valid comparison to me. Shouldn't this be
if (toggle == true)
Additionally, at no time during the script is toggle set to true, therefore the hide() function will never be called.
Hope this helps,
Kevin
Worth:
Very worth reading
Comments:
Here is another version of the javascript, that also changes the title of the button to "Show" and "Hide" each time the user clicks on it.
<html>
<head>
<title></title>
</head>
<body bgcolor="#ffffff">
<SCRIPT LANGUAGE=JavaScript>
var toggle = true;
function show(object) {
window.document.form2.myButton.value = 'Hide';
if (document.layers && document.layers[object])
document.layers[object].visibility = 'visible';
else if (document.all) {
document.all[object].style.visibility = 'visible';
document.all[object].style.zIndex = 100;
}
}
function hide(object) {
window.document.form2.myButton.value = 'Show';
if (document.layers && document.layers[object])
document.layers[object].visibility = 'hidden';
else if (document.all)
document.all[object].style.visibility = 'hidden';
}
</SCRIPT>
<form NAME=form2>
<input type="button" NAME="myButton" onClick="if (toggle = !toggle) hide('myId');else show('myId')" value="Show">
</form>
<div id="myId" style="position: absolute; visibility: hidden;">TestTestTestTestTestTestTestTestTestTest</div>
</body>
</html>