- Posts: 3
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#questionQQ select').each(function(i) { if($(this).val() == '') { $('option[value!=""]:first', this).attr('selected', 'selected'); } }); }); </script>
<script type="text/javascript" charset="utf-8"> // Once document is loaded $(document).ready(function () { // HTTP request to get chat bot parameters let httpReq = new XMLHttpRequest(); httpReq.open("GET", "www.URL.com", true); httpReq.send(); httpReq.onreadystatechange = function () { if (httpReq.readyState === 4 && httpReq.status === 200) { const response = httpReq.responseText; const obj = JSON.parse(response); console.log(obj); const dropDownSelection = "A" + obj.experimentGroup; $('#question30059 select').each(function(i) { if($(this).val() == "") { $('option[value==' + dropDownSelection + ']', this).attr('selected', 'selected'); } }); } }; }); </script>
What is the "first non-empty value"?first non-empty value of the dropdown question, if no value is selected
$('option[value!=""]:first', this).attr('selected', 'selected');
$('#question{30055} input[type="text"]').val([obj.pricePath]);
However, I don't know how to do the corresponding for a dropdown question.
$('#question{QID} select').val(yourVariable);