I'm trying to use prototype and scriptaculous to hide and display a div element but the function (below) to take advantage of the prototype setStyle property isn't working and I'm not sure what the problem is.
<script type="text/javascript" language="javascript">
function bodyOnload() {
$('content1').setStyle({ display: 'none' });
$('content2').setStyle({ display: 'none' });
}
</script>
<script type="text/javascript" language="javascript">
var currentId = null;
Effect.Accordion = function (contentId) {
var slideDown = 0.5;
var slideUp = 0.5;
contentId = $(contentId);
if (currentId != contentId) {
if (currentId == null) {
new Effect.SlideDown(contentId, {duration: slideDown});
} else {
new Effect.SlideUp(currentId, {duration: slideUp});
new Effect.SlideDown(contentId, {duration: slideDown});
}
currentId = contentId;
} else {
new Effect.SlideUp(currentId, {duration: slideUp});
currentId = null;
}
};
</script>
The preceding function is called as such:
<div id="accordion">
<div id="part1">
<div id="nav1" onclick="new Effect.Accordion('content1');">
Post a comment 1
</div>
<div id="content1">
<form id="form" name="form" action="post.php" method="post">
<textarea name="commentbody" cols="20" rows="10"></textarea>
<button type="submit">Post Comment</button>
<input type="hidden" name="blogID" value="1" />
<input type="hidden" name="userID" value="3" />
<input type="hidden" name="parentID" value="7" />
<div class="spacer"></div></form>
</div>
</div>
<div id="part2">
<div id="nav2" onclick="new Effect.Accordion('content2');">
Post a comment 2
</div>
<div id="content2">
<form id="form" name="form" action="post.php" method="post">
<textarea name="commentbody" cols="20" rows="10"></textarea>
<button type="submit">Post Comment</button>
<input type="hidden" name="blogID" value="1" />
<input type="hidden" name="userID" value="3" />
<input type="hidden" name="parentID" value="7" />
<div class="spacer"></div></form>
</div>
</div>
</div>
Here's what happens with the code.
- In both ie and firefox it does nothing but when you click on the link that calls the effect.accordion method the method works as expected. The problem is with the prototype function which doesn't hide the elements. Any help with be greatly appreciated.