- Posts: 169
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$(this).closest('td').find('input[type="text"]').val(legPerPet.val*PetNumber.val);
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var qID = {QID}; // Insert the new dropdowns var numLegsSelect = '<select class="insertedSelect numLegs"> \ <option value="">Choose pet type...</option> \ <option value="4">Dog</option> \ <option value="2">Parrot</option> \ </select>'; var numPetsSelect = '<select class="insertedSelect numPts"> \ <option value="">Choose number of pets...</option> \ <option value="1">1</option> \ <option value="2">2</option> \ <option value="3">3</option> \ <option value="4">4</option> \ <option value="5">5</option> \ <option value="6">6</option> \ <option value="7">7</option> \ <option value="8">8</option> \ <option value="9">9</option> \ <option value="10">10</option> \ </select>'; $('#question'+qID+' .answer_cell_00N1').append(numLegsSelect).append(numPetsSelect); // Hide the LS selects $('#question'+qID+' .answer_cell_00N1 .multiflexiselect').hide(); // Listener on the inserted dropdowns $('.insertedSelect').change(function() { var thisCell = $(this).closest('td'); $('.multiflexiselect', thisCell).val($('.numLegs', thisCell).val()*$('.numPts', thisCell).val()); }); }); </script>
.closest('td')
i don't know what's the meaning of closest('td'), then i checked the manual, i didnot find predefined variables list in manual, then it's not easy to design various type question.multiflexiselect
$('#question'+qID+' .answer_cell_00N1 .multiflexiselect').each(function(i){ if($(this).val()>0) { if(4==4){ $(this).closest('td').find('.insertedSelect').val($('.numPts', thisCell).val()/4); $(this).closest('td').find('.insertedSelect').val($('.numLegs', thisCell).val('dog'));} else { $(this).closest('td').find('.insertedSelect').val($('.numPts', thisCell).val()/2); $(this).closest('td').find('.insertedSelect').val($('.numLegs', thisCell).val('parrot'));} } });
$(this).closest('td').find('.insertedSelect').val($('.numPts', thisCell).val()/4); $(this).closest('td').find('.insertedSelect').val($('.numLegs', thisCell).val('dog'))