Welcome to the LimeSurvey Community Forum

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

Prefill an array(Text) from a previous array(Text)

  • krosser
  • krosser's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 5 months ago #176892 by krosser
Hi guys,

I have to split a table and present it as two arrays with text inputs. Some answers/text inputs should be identical in both tables. So, I need to prefill certain text inputs in the 2nd array table, when the answers are typed in in the 1st table. I guess that is not possible with the subquestion validation or relevance equation, is it? I couldn't figure out the correct syntax. Would appreciate any help..

For example, "text 1" should appear in the 2nd array as "text 1" and so on...


A test survey attached..

File Attachment:

File Name: limesurvey...5243.lss
File Size:22 KB

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
  • krosser
  • krosser's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 5 months ago #176898 by krosser
Okay, guys. I've managed to do it with a JS code. For my particular example it is

Code:
<script type="text/javascript">
  $(document).ready(function () {
    $('#answer715243X12X689Y01_X01').on('change', function (e) {
       $('#answer715243X12X698Y01_X01').val($('#answer715243X12X689Y01_X01').val());
       });
    $('#answer715243X12X689Y02_X01').on('change', function (e) {
       $('#answer715243X12X698Y02_X01').val($('#answer715243X12X689Y02_X01').val());
        });
    $('#answer715243X12X689Y03_X01').on('change', function (e) {
       $('#answer715243X12X698Y03_X01').val($('#answer715243X12X689Y03_X01').val());
      });
});
</script>


If someone thinks there is a better way, please let me know :)

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176938 by DenisChenu
The only solution to get it in same page.

You can use {SGQ} then if you copy the survey : don't need updatinf javascript

Code:
$(document).ready(function () {
    $('#answer{SGQ}Y01_X01').on('change', function (e) {
       $('#answer{that.Q2.sgqa}Y01_X01').val($(this).val());
       });
    $('#answer{SGQ}Y02_X01').on('change', function (e) {
       $('#answer{that.Q2.sgqa}Y02_X01').val($(this).val());
        });
    $('#answer{SGQ}Y03_X01').on('change', function (e) {
       $('#answer{that.Q2.sgqa}Y03_X01').val($(this).val());
      });
});

Else : you don't really need the Q2 X1 value ? User must not update it ? Right ?

If right : maybe someting like this


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.
  • krosser
  • krosser's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 5 months ago #176953 by krosser
Thanks man, but the script isn't working. I have tried to adjust Y and X there but still, nothing changes...

Regarding your second option, looks cool. I wouldn't be able to figure out the syntax myself. But I'd like to keep the numbers in the 1st subquestion column. It would be great if it was possible to do that for the answer choice column.

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #176967 by DenisChenu
No, you need to put the answer on 1st columns … :/

Maybe some javascript solution …

About #answer{SGQ}Y01_X01' : it work if you put the script in question text (or use addScriptToQuestion ).

But you can't use it anywhare else (and maybe i make some error ;))

It use manual.limesurvey.org/Expression_Manager#Access_to_Variables , in question 698 in group 12 in surevy 715243 : {SGQ} must give 715243X12X698

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.

Lime-years ahead

Online-surveys for every purse and purpose