Changing group title via javascript

More
3 months 1 week ago #159374 by jkautto
jkautto created the topic: Changing group title via javascript
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):
<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?

Please Log in to join the conversation.

More
3 months 1 week ago #159387 by fvanderstarre
fvanderstarre replied the 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

Please Log in to join the conversation.

More
3 months 1 week ago - 3 months 1 week ago #159390 by jkautto
jkautto replied the 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: 3 months 1 week ago by jkautto. Reason: text improvements

Please Log in to join the conversation.

More
3 months 1 week ago - 3 months 1 week ago #159402 by tpartner
tpartner replied the 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:

<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: 3 months 1 week ago by tpartner.
The following user(s) said Thank You: jkautto

Please Log in to join the conversation.

More
3 months 1 week ago #159411 by jkautto
jkautto replied the 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

Please Log in to join the conversation.

More
3 months 1 week ago #159415 by jkautto
jkautto replied the topic: Changing group title via javascript
addition: My template is "news_paper" with few minor modifications.

Please Log in to join the conversation.

More
3 months 1 week ago #159433 by DenisChenu
DenisChenu replied the 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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 week 5 days ago - 1 week 5 days ago #162224 by jkautto
jkautto replied the 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:

<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: 1 week 5 days ago by jkautto.

Please Log in to join the conversation.

More
1 week 5 days ago #162229 by tpartner
tpartner replied the 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.

<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

Please Log in to join the conversation.

More
1 week 5 days ago #162230 by jkautto
jkautto replied the 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)?

Please Log in to join the conversation.

More
1 week 5 days ago #162232 by tpartner
tpartner replied the 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

Please Log in to join the conversation.

More
1 week 5 days ago #162234 by jkautto
jkautto replied the topic: Changing group title via javascript
Now the scripts are working again (I disabled XSS from config), except for the line
var N_total = {NUMBEROFGROUPS};
which does nothing. Maybe there is still some option that I need to change.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!