- Posts: 12
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Changing group title via javascript
- jkautto
- Topic Author
- Offline
- New Member
Less
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 is in group description (same for each group). I have version 2.70. Can someone help?
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.
- fvanderstarre
- Offline
- Elite Member
Less
More
- Posts: 176
- Thank you received: 36
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
6 years 5 months ago - 6 years 5 months ago #159402
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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:
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.
Attachments:
Last edit: 6 years 5 months ago by tpartner.
The following user(s) said Thank You: jkautto
The topic has been locked.
- jkautto
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
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
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13907
- Thank you received: 2546
6 years 5 months ago #159433
by DenisChenu
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.
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
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:
Can someone please tell me how to get javascript work and maybe convert my previous code suitable for version 3? Thanks.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
6 years 2 months ago #162229
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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.
Attachments:
The following user(s) said Thank You: jkautto
The topic has been locked.
- jkautto
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
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)?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
6 years 2 months ago #162232
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Changing group title via javascript
Yes.Ok, so basically javascript should work out-of-the-box same as before...
No, notice that there is a slight difference in the jQuery selectors in the script that I provided for 3.0.1....and my old imported 2.73 survey should also work?
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
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
which does nothing. Maybe there is still some option that I need to change.
Code:
var N_total = {NUMBEROFGROUPS};
The topic has been locked.