/    Sign up×
Community /Pin to ProfileBookmark

Toggle div visibilty

Hi all,

I have a div I would like to show and hide.

I’ve used a script before which works, but now reusing it I can’t make it fly. As I can’t see where I am going wrong, can anyone else help?

This is the one that works:

[code=html]
<!–script in head tag –>
<script type=”text/javascript”>
<!–
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
if(document.layers) //NN4+
{
document.layers[szDivID].visibility = iState ? “show” : “hide”;
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState ? “visible” : “hidden”;
}
else if(document.all) // IE 4
{
document.all[szDivID].style.visibility = iState ? “visible” : “hidden”;
}
}
// –>
</script>

<body>
<div id=”positioned-element25″>
<a href=”#” onClick=”toggleBox(‘login’,1);”>Login</a></div>
<div id=”login”>
<form name=”fp_login” action=”prcs_login.php” method=”post”>
<table>
<!– abbreviated –>
<tr>
<td>

<td>
<input type=”button” onClick=”toggleBox(‘login’,0);” value=”Cancel”>
</td>
</tr>

</table>
</form>
</div>
[/code]

…and this is the new version:

[code=html]
<script type=”text/javascript”>
<!–
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
if(document.layers) //NN4+
{
document.layers[szDivID].visibility = iState ? “show” : “hide”;
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState ? “visible” : “hidden”;
}
else if(document.all) // IE 4
{
document.all[szDivID].style.visibility = iState ? “visible” : “hidden”;
}
}
// –>
</script>
<body>
<div id=”positioned-element25″>
<a href=”#” onClick=”toggleBox(‘login’,1);”>Login</a></div>
<div id=”login”>
<?php
include (‘mailer.php’);
?>
</div>

[/code]

I can’t see the difference, but the top one works and not the bottom. Pointers please?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@donatelloOct 25.2009 — Look in your style sheet!

That is where the answer is...

?
×

Success!

Help @AliHurworth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...