I know very little about JavaScript but I found this snippit and I am trying to use it. I have 2 probelms - first, how to get all of the answers to be hidden on default (they currently display on default) and second how to make the view all work but in link form not checkbox (it is currently in checkbox form but does not work and I can't figure out why).
Thanks in advance for any help!Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> window.onload = onLoad; function onLoad() { var sa = document.getElementById("chkViewAll"); if(typeof(IsPrinterFriendly) == "undefined") sa.checked = false; else sa.checked = true; } function toggleQuestions(checked) { var secCount = 5; var faqEntryCount = 37; for(var j=1; j<=secCount; j++) { for (var i=1; i<=faqEntryCount; i++) { var title = document.getElementById("title" + j + i); if(checked == true) expandQuestion("title" + j + i, "question" + j +i, "answer" + j + i); else collapseQuestion("title" + j + i, "question" + j +i, "answer" + j + i); } } if(checked == false) { var sa = document.getElementById("chkViewAll"); sa.checked = false; } } function toggleQuestion(tName, qName, aName) { var title = document.getElementById(tName); if (title == null) return; var ans = document.getElementById(aName); if (ans == null) return; var que = document.getElementById(qName); if (ans.style.display == '') { if (que != null) que.style.display = 'none'; ans.style.display = 'none'; var sa = document.getElementById("chkViewAll"); sa.checked = false; } else { if (que != null) que.style.display = ''; ans.style.display = ''; } } function expandQuestion(tName, qName, aName) { var title = document.getElementById(tName); if (title == null) return; var ans = document.getElementById(aName); if (ans == null) return; var que = document.getElementById(qName); if (que != null) que.style.display = ''; ans.style.display = ''; } function collapseQuestion(tName, qName, aName) { var title = document.getElementById(tName); if (title == null) return; var ans = document.getElementById(aName); if (ans == null) return; var que = document.getElementById(qName); if (que != null) que.style.display = 'none'; ans.style.display = 'none'; } </script> </head> <body> <script language="Javascript"> document.write('<div id="selectAll" style="margin-top:10px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="right"><input id="chkViewAll" type="checkbox" onclick="toggleAll()"></td><td class="selectAll">View all answers</td></tr></table></div>'); </script> <div id="title10" class="body"><a href="javascript:toggleQuestion('title10', 'question10', 'answer10')">Question 1?</a></div> <div id="answer10" class="body">Answer 1.</div> <div id="title11" class="body"><a href="javascript:toggleQuestion('title11', 'question11', 'answer11')">Question 2?</a></div> <div id="answer11" class="body">Answer 2.</div> <div id="title12" class="body"><a href="javascript:toggleQuestion('title12', 'question12', 'answer12')">Question 3?</a></div> <div id="answer12" class="body">Answer 3</div> </body> </html>



Reply With Quote

Bookmarks