Welcome to the LimeSurvey Community Forum

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

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

  • bruce78
  • bruce78's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago #164656 by bruce78
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?

Code:
<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()!="" &amp;&amp; $(this).val()!="-oth-"){
    $("#movenextbtn,#movesubmitbtn").delay(1).click();
    }
  });
 
  $('#movenextbtn, #movesubmitbtn').hide();
 
});
</script>
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #164657 by Joffm
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 topic has been locked.
  • bruce78
  • bruce78's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago #164660 by bruce78

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
Code:
tr.radio-list
to
Code:
td.radio-item
and
Code:
.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?

Code:
<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()!="" &amp;&amp; $(this).val()!="-oth-"){
    $("#ls-button-submit").delay(1).click();
    }
  });
 
  $('#ls-button-submit').hide();
 
});
</script>
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #164661 by Joffm
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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago - 6 years 1 month ago #164663 by Joffm
Hi, bruce,
I found this in
www.limesurvey.org/forum/can-i-do-this-w...ter-selecting-answer
three days ago.

Autoproceed of radios.
Code:
<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: 6 years 1 month ago by Joffm.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #164666 by tpartner
Yes, there is no longer a "radio" class assigned to the inputs so you need to use the type selector:

Code:
<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()!="" &amp;&amp; $(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.
The topic has been locked.
  • bruce78
  • bruce78's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago #164699 by bruce78
Great, thank you - that seems to have worked after a quick test! I'll see how I get on...
The topic has been locked.
  • bruce78
  • bruce78's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago #164709 by bruce78
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?
The topic has been locked.
  • bruce78
  • bruce78's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago #165312 by bruce78
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...

Code:
UPDATE `ls_db`.`ls_table`
SET `ls_field` = replace(ls_field, 'unwanted_text', 'wanted_text');
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose