Welcome to the LimeSurvey Community Forum

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

Changing group title via javascript

  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 5 months ago #159374 by jkautto
Changing group title via javascript was created by jkautto
Hi

I want to add progress information into the group title, i.e., group title should say something like ''this is page 6 out of 24''. This should be simple, but I don't know the correct javascript commands to do it.
I have tried this code without luck (nothing happens):
Code:
<script type='text/javascript'>
   $(document).ready(function() {
       var N_total = {NUMBEROFGROUPS};
       var N_current = $("#thisstep").val();
       $(".grouptitle").text("this is page " + N_current + " out of " + N_total);
});
</script>

Code is in group description (same for each group). I have version 2.70. Can someone help?
The topic has been locked.
More
6 years 5 months ago #159387 by fvanderstarre
Replied by fvanderstarre on topic Changing group title via javascript
Since your message seems to be fixed for each group, why not put it directly in the group title without using any script or variables?
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 5 months ago - 6 years 5 months ago #159390 by jkautto
Replied by jkautto on topic Changing group title via javascript
Title should tell the current page with group randomization enabled, hence it cannot be fixed. Group title should work like the progress bar with page numbers instead of percentages. I already changed the progress bar to show step information (format "step 5 out of 57" etc.) via javascript, but I also want to include this information in titles.

PS. Without group randomization, I would not need scripting (I could fix titles when creating the survey). You are correct there.
Last edit: 6 years 5 months ago by jkautto. Reason: text improvements
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 5 months ago - 6 years 5 months ago #159402 by tpartner
Replied by tpartner on topic Changing group title via javascript
What template are you using and where did you find the selector ".grouptitle"?

I find that this works with the default template:

Code:
<script type='text/javascript'>
  $(document).ready(function() {
    var N_total = {NUMBEROFGROUPS};
    var N_current = $("#thisstep").val();
    $(".group-name").text("This is page " + N_current + " out of " + N_total);
    $(".group-description-container").hide();
  });
</script>


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 5 months ago by tpartner.
The following user(s) said Thank You: jkautto
The topic has been locked.
  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 5 months ago #159411 by jkautto
Replied by jkautto on topic Changing group title via javascript
Thanks, your code works perfectly! It also seem to work without the last command, i.e., "$(".group-description-container").hide();".

I found ".grouptitle" from this thread:

www.limesurvey.org/forum/can-i-do-this-w...ion-group-in-tempate
The topic has been locked.
  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 5 months ago #159415 by jkautto
Replied by jkautto on topic Changing group title via javascript
addition: My template is "news_paper" with few minor modifications.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 5 months ago #159433 by DenisChenu
Replied by DenisChenu on topic Changing group title via javascript
We didn't add {STEP} in core expression manager ? Must be done …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago - 6 years 2 months ago #162224 by jkautto
Replied by jkautto on topic Changing group title via javascript
It seem this code no longer works with Limesurvey 3.0.1. In fact, I can't get any javascript to run with version 3, not even this example given in the official Manual:

Code:
<script type="text/javascript" charset="utf-8">
   $(document).on('ready pjax:complete',function() {
       alert("Test!");
   });
</script>


Can someone please tell me how to get javascript work and maybe convert my previous code suitable for version 3? Thanks.
Last edit: 6 years 2 months ago by jkautto.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #162229 by tpartner
Replied by tpartner on topic Changing group title via javascript
You may have a JavaScript error. This works for me in the vanilla and the bootswatch themes of 3.0.1.

Code:
<script type='text/javascript'>
  $(document).ready(function() {
    var N_total = {NUMBEROFGROUPS};
    var N_current = $("#thisstep").val();
    $(".group-title").text("This is page " + N_current + " out of " + N_total);
    $(".group-description-container").hide();
  });
</script>


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: jkautto
The topic has been locked.
  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #162230 by jkautto
Replied by jkautto on topic Changing group title via javascript
Ok, so basically javascript should work out-of-the-box same as before and my old imported 2.73 survey should also work?

I installed both XAMPP version 2.73 and 3.0.1 (no mods) but cannot get any javacripts to run with version 3. No errors show up, scripts simply have no any effect.

Is there live demo for version 3 where I could do some testing (demo.limesurvey.org is still 2.72)?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago #162232 by tpartner
Replied by tpartner on topic Changing group title via javascript

Ok, so basically javascript should work out-of-the-box same as before...

Yes.

...and my old imported 2.73 survey should also work?

No, notice that there is a slight difference in the jQuery selectors in the script that I provided for 3.0.1.

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: jkautto
The topic has been locked.
  • jkautto
  • jkautto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 2 months ago #162234 by jkautto
Replied by jkautto on topic Changing group title via javascript
Now the scripts are working again (I disabled XSS from config), except for the line
Code:
var N_total = {NUMBEROFGROUPS};
which does nothing. Maybe there is still some option that I need to change.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose