Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How does JavaScript work?

  • free521521521
  • free521521521's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 9 months ago #242050 by free521521521
How does JavaScript work? was created by free521521521
Please help us help you and fill where relevant:
Your LimeSurvey version: [url=https://localhost:8888/limesurvey/index.php?r=questionAdministration/view&surveyid=772959&gid=14&qid=214#modalSystemInformation]Version 5.6.11+230320[/url]
Own server or LimeSurvey hosting:loalhost
Survey theme/template: fruit_exteded
==================
I read this:  www.limesurvey.org/manual/Workarounds:_M...ime_using_Javascript
I wan to add a collpase tab in text display question to avoid a extremly long page, I found it could works with JS  code. So I tried those:
1. Turn "Filter HTML for XSS" to off.
2a. I add JS to extended survey theme custom.js. save it
2b. I add JS to question by source editor.
BUT, the Neither of them works. This page show fine, but when you click the tab, it just refresh the page. The collapse tab did not extended.

This is the code I used in source editor:
Code:
 
<style>
.collapsible {
  background-color: #777;
  color: white;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
}
 
.active, .collapsible:hover {
  background-color: #555;
}
 
.collapsible:after {
  content: '\002B';
  color: white;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}
 
.active:after {
  content: "\2212";
}
 
.content {
  padding: 0 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background-color: #f1f1f1;
}
</style>
 
 
<h2>Animated Collapsibles</h2>
 
<p>A Collapsible:</p>
<button class="collapsible">Open Collapsible</button>
<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
 
<p>Collapsible Set:</p>
<button class="collapsible">Open Section 1</button>
<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<button class="collapsible">Open Section 2</button>
<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<button class="collapsible">Open Section 3</button>
<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
 
<script>
var coll = document.getElementsByClassName("collapsible");
var i;
 
for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    if (content.style.maxHeight){
      content.style.maxHeight = null;
    } else {
      content.style.maxHeight = content.scrollHeight + "px";
    } 
  });
}
</script>
I upload the lss file as well.
 

File Attachment:

File Name: limesurvey...8939.lss
File Size:23 KB

Thanks for helping me!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #242057 by Joffm
Replied by Joffm on topic How does JavaScript work?
Hi,
as LimeSurvey is based on bootstrap 3.x. you may use the bootstrap features.
[url] getbootstrap.com/docs/3.3/javascript/#collapse [/url]

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu, tpartner, free521521521

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #242061 by tpartner
Replied by tpartner on topic How does JavaScript work?
I agree, don't re-invent the wheel, use Bootstrap as Joffm suggests.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: free521521521

Please Log in to join the conversation.

  • free521521521
  • free521521521's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 9 months ago #242066 by free521521521
Replied by free521521521 on topic How does JavaScript work?
WOW! I didn't know that before, thanks al lot!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose