Forum Moderators: open

Message Too Old, No Replies

very very very basic and easy

         

ayushchd

7:45 pm on Sep 1, 2007 (gmt 0)

10+ Year Member



Why is this not working?

<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?

rocknbil

4:44 am on Sep 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The FireFox error console rocks. :-)

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>

ayushchd

2:18 pm on Sep 2, 2007 (gmt 0)

10+ Year Member



What I have to show multiple divs...like:

window.onLoad = function() { showdiv('name'); , showdiv('email'); };