- Posts: 58
- Thank you received: 9
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var qIDpro = {QID}; var qProvinceCode = $('#question'+qIDpro).nextAll('.text-short:eq(0)'); var qComune = $('#question'+qIDpro).nextAll('.text-short:eq(1)'); var qComuneCode = $('#question'+qIDpro).nextAll('.text-short:eq(2)'); var url = "{TEMPLATEURL}provcode.csv"; var url2 = "{TEMPLATEURL}comcod2016.csv"; var province = []; var comune = []; // Hide the code questions qProvinceCode.hide(); qComuneCode.hide(); // Get the comune CSV fullArray2 = []; $.get(url2,function(data){ // Convert CSV contents to an array of arrays fullArray2 = $.csv.toArrays(data); }); // Get the province CSV $.get(url,function(data){ // Convert CSV contents to an array of arrays fullArray = $.csv.toArrays(data); // Load the province data array $(fullArray).each(function(i, item){ province.push(item[0]); }); // Initialise the autocomplete plugin for province $('#question'+qIDpro+' input.text').autocomplete({ source: province, select: function(event, ui) { // Load the hidden "Province Code" question var thisValue = ui.item.value; $(fullArray).each(function(i, item){ if(item[0] == thisValue) { var provinceCode = item[1]; $('input.text', qProvinceCode).val(provinceCode); // Load the comune data array comune = []; $(fullArray2).each(function(i, item){ if(item[2] == provinceCode) { comune.push(item[0]); } }); // Reset comune and code $('input.text', qComune).val('').autocomplete().autocomplete('destroy'); $('input.text', qComuneCode).val(''); // Initialise the autocomplete plugin for comune $('input.text', qComune).autocomplete({ source: comune, select: function(event, ui) { // Load the hidden "Comune Code" question var thisValue = ui.item.value; $(fullArray2).each(function(i, item){ if(item[0] == thisValue) { var comuneCode = item[1]; $('input.text', qComuneCode).val(comuneCode); } }); } }); } }); } }); }); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var q2ID = {QID}; var url = "{TEMPLATEURL}provcode.csv"; var province2 = []; // Get the province CSV $.get(url,function(data){ // Convert CSV contents to an array of arrays fullArray2 = $.csv.toArrays(data); // Load the province data array $(fullArray2).each(function(i, item){ province2.push(item[0]); }); // Initialize the autocomplete plugin $('#question'+q2ID+' input[type="text"]').autocomplete({ source: province2 }); }); }); </script>