Forum Moderators: open
<script language="javascript">
function showdiv(id) {
if (document.getElementById){
obj2 = document.getElementById(id);
if (obj2.style.display == "none"){
obj2.style.display = "";
}
}
}
function hidediv(id1) {
if (document.getElementById){
obj = document.getElementById(id1);
if (obj.style.display == ""){
obj.style.display = "none";
}
}
}
window.onLoad = showdiv(hemail);
</script>
window.onload?
Error: hemail is not defined
So we do this
window.onLoad = showdiv('hemail');
And still get
Error: obj2 has no properties
test.html
so we do this
window.onLoad = function() { showdiv('hemail'); };
to predefine the function because hemail is not loaded when it executes the onLoad.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype on one line -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>hide div</title>
<script type="text/javascript">
function showdiv(id) {
if (document.getElementById){
obj2 = document.getElementById(id);
if (obj2.style.display == 'none'){
obj2.style.display = '';
}
}
}
function hidediv(id1) {
if (document.getElementById){
obj = document.getElementById(id1);
if (obj.style.display == ''){
obj.style.display = 'none';
}
}
}
window.onload = function() { showdiv('hemail'); };
</script>
</head>
<body>
<div id="hemail" style="display:none;">
<a href="#" onClick="hidediv('hemail');">hide me</a>
</div>
<div id="showme">
<a href="#" onClick="showdiv('hemail');">show hemail</a>
</div>
</body>
</html>