javascript function toggle(..) to hide/show text or activities
I tried to implement the javascipt function toggle(..) in my new module. In order to test this function, I tried to hide/show div-tags in mynewmod/view.php but this way it's not working:
echo "<script language='javascript'>
function toggle(targetId) {
target = document.all(targetId);
if (target.style.display == 'none'){
target.style.display='';
} else {
target.style.display='none';
}
}
//-->
</script>";
echo "<a href='javascript:toggle(\"Link1\")'>Link 1 </a>
<div id='Link1' style='display: none'>
<div align='justify'>Here is the text you would like to show for Link 1.</font></div>
</div>";
Would be nice if anybody can tell me how to fix this.
My idea is to implement a new course format where I toggle the visibility of activity modules. Does anybody has a solution with YUI for my problem??
Thx for any advice
Ingo
Re: javascript function toggle(..) to hide/show text or activities
Development:JavaScript_guidelines tries to explain the right way to do it.
Re: javascript function toggle(..) to hide/show text or activities
Hi Tim - I am trying to do the same thing.
Rather than discussing the moralities of coding, I wonder if there is documentation of the functions available in javascript-static.js?
I am thinking that perhaps there is already a show/hide <div> function available - and perhaps a YUI or jQuery call rather than an inline href?
I just learned about YUI and jQuery about 7 minutes ago.
Then the trick becomes training your content providers to not delete ur <div>s!
thanks moodle community!
Re: javascript function toggle(..) to hide/show text or activities
Replying to myself - trying to track down how to use the function "elementToggleHide" in javascript-statis.js
I can only find a very few examples and nothing I'd consider documentation.
Been trying to make this example work (from URS and it's returned in several places by googling):
<div class="hide-show"><a href="#" onclick="elementToggleHide(this, true,
function(el) {return findParentNode(el, 'DIV', 'sideblock'); } ); return
false;"><img src="http://moodle.eb-zuerich.ch/pix/spacer.gif" alt="" class="hide-show-image"></a></div>Hauptmenü</div></div>
Oh, and it's using an inline javascript!
From this page:
http://www.nabble.com/Component-Template-td4661021.html