Disable an Array element and show Sum of other same Array elements in that disabled field using Lime Survey?

292 Views Asked by At

Does anyone know how to Disable an Array element and show Sum of other same Array elements in that disabled field using Lime Survey?

For example: we have Question type: Array (Texts)

Array (xx1,xx2,xx3,xx4)

Here I want to disable xx1 field and show Sum of xx2 and xx3 in the disabled field.

I tried disabled the field with following codes (based on search results) but none of them seems to work

<script type="text/javascript" charset="utf-8">
   $(document).ready(function() {
        $('array-multi-flexi[id="q1_x1_y1"]').attr('disabled', 'disabled');
        $('array[id="q1_x1_y1"]').attr('disabled', 'disabled');
        $('input[name="q1_x1_y1"]').hide();
       $('array-multi-flexi[name="q1_x1_y1"]').hide();
       $('input[name="#answertextq1_x1_y1"]').attr('disabled', 'disabled');
   });
 </script>

Question in the form of an image

x

Thanks

1

There are 1 best solutions below

0
Apache On

Found a solution to my question. If anyone has similar case below is my code:

desc:

  1. #limesurvey is the main form name.
  2. parseFloat function is used otherwise values are appended as if strings.

<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $('input[id="answer752589X30X2319x1_y1"]').attr('disabled', 'disabled');});
    
    $("#limesurvey").on("change", function(event) { 
         var k = parseFloat($('input[id="answer752589X30X2319x2_y1"]').val());
         var l = parseFloat($('input[id="answer752589X30X2319x3_y1"]').val());
         var m = k+l;
         $('input[id="answer752589X30X2319x1_y1"]').val(m);
});
</script>