How to auto-advance to the next question in Version 3

More
7 months 2 weeks ago #164656 by bruce78
bruce78 created the topic: How to auto-advance to the next question in Version 3
In version 2, the following script would hide the 'Next' button and automatically load the next question once an answer was clicked. However, in version 3, this behaviour no longer works...

Does anyone know how I can update the javascript below such that drop down and radio button questions auto-advance?

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
 
	$('tr.radio-list input.radio').bind('click', function () {			
		var thisArray = $(this).closest('table');
		if($('input.radio:checked', thisArray).length == $('tr.radio-list', thisArray).length) {
			$("#movenextbtn,#movesubmitbtn").delay(1).click();
		}
	});
 
	$(".list-dropdown select").change(function(){
		if($(this).val()!="" && $(this).val()!="-oth-"){
		$("#movenextbtn,#movesubmitbtn").delay(1).click();
		}
	});
 
	$('#movenextbtn, #movesubmitbtn').hide();
 
});
</script>

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago #164657 by Joffm
Joffm replied the topic: How to auto-advance to the next question in Version 3
Hi, bruce,

in version 3. the "#movenextbtn,#movesubmitbtn" have other IDs.
Now it is "#ls-button-submit"

Check by using a webdeveloper tool.

Joffm


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

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago #164660 by bruce78
bruce78 replied the topic: How to auto-advance to the next question in Version 3

Joffm wrote: in version 3. the "#movenextbtn,#movesubmitbtn" have other IDs.
Now it is "#ls-button-submit"


Thank you Joffm - the code below now hides the 'Next' button and auto-advances on dropdown questions but nothing happens on radio button array questions...

Looking at the developer tools in Google, I've tried changing
tr.radio-list
to
td.radio-item
and
.radio-item
with no joy... do you know what else I need to change for the auto advancing to work on radio array type questions?

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
 
	$('tr.radio-list input.radio').bind('click', function () {			
		var thisArray = $(this).closest('table');
		if($('input.radio:checked', thisArray).length == $('tr.radio-list', thisArray).length) {
			$("#ls-button-submit").delay(1).click();
		}
	});
 
	$(".list-dropdown select").change(function(){
		if($(this).val()!="" && $(this).val()!="-oth-"){
		$("#ls-button-submit").delay(1).click();
		}
	});
 
	$('#ls-button-submit').hide();
 
});
</script>

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago #164661 by Joffm
Joffm replied the topic: How to auto-advance to the next question in Version 3
Hi, bruce,
yes, the radios are different, because it is not table-based anymore.

But - to be honest - I am not very familiar with JS. Therefore no solution from my side, sorry.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago - 7 months 2 weeks ago #164663 by Joffm
Joffm replied the topic: How to auto-advance to the next question in Version 3
Hi, bruce,
I found this in
https://www.limesurvey.org/forum/can-i-do-this-with-limesurvey/108498-automatically-proceed-to-next-question-after-selecting-answer
three days ago.

Autoproceed of radios.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){ 
		$('#question{QID} input[type="radio"]').on('click', function() {
			$('#ls-button-submit').trigger('click');
		});
	});	
</script>

Regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last Edit: 7 months 2 weeks ago by Joffm.

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago #164666 by tpartner
tpartner replied the topic: How to auto-advance to the next question in Version 3
Yes, there is no longer a "radio" class assigned to the inputs so you need to use the type selector:

<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		$('tr.radio-list input[type="radio"]').bind('click', function () {			
			var thisArray = $(this).closest('table');
			if($('input[type="radio"]:checked', thisArray).length == $('tr.radio-list', thisArray).length) {
				$("#ls-button-submit").delay(1).click();
			}
		});
 
		$(".list-dropdown select").change(function(){
			if($(this).val()!="" && $(this).val()!="-oth-"){
			$("#ls-button-submit").delay(1).click();
			}
		});
 
		$('#ls-button-submit').hide();
 
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago #164699 by bruce78
bruce78 replied the topic: How to auto-advance to the next question in Version 3
Great, thank you - that seems to have worked after a quick test! I'll see how I get on...

Please Log in or Create an account to join the conversation.

More
7 months 2 weeks ago #164709 by bruce78
bruce78 replied the topic: How to auto-advance to the next question in Version 3
If I want to do a find/replace type exercise in mysql to update the script to this new code, are there any pointers or tips for LimeSurvey? The scripts are all inserted into the question source with the corresponding <script> tags...

I know some people talk about serialisation as something to watch out for in WordPress but are there any issues to be aware of that might affect LimeSurvey at all?

Please Log in or Create an account to join the conversation.

More
7 months 4 days ago #165312 by bruce78
bruce78 replied the topic: How to auto-advance to the next question in Version 3
ok, so having looked into this, the mysql statement below seems to work fine as a way of mass updating strings in questions or in other fields...

if you run into problems with charachters that need to be escaped and this includes a lot of punctuation, quotes, hashes and so on, mysql workbench is a quick way to check your syntax...

UPDATE `ls_db`.`ls_table`
SET `ls_field` = replace(ls_field, 'unwanted_text', 'wanted_text');

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!