Adding Autocomplete with Javascript to Qualtrics

天涯浪子 提交于 2019-12-08 08:14:43

问题


I'm trying to implement an autocomplete feature to Qualtrics online survey management software. As directed in this feature on the Qualtrics website, I've added the main features of the code to the header of it's Look and Feel section.

<br />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script><script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script><script>

var $j = jQuery.noConflict();  
 $j(function() {
var availableTags = [
  "Selection 1",
  "Selection 2",
  "Selection 3"
];
$j( "#tags" ).autocomplete({
  source: availableTags
});
});
</script>

Also, I've added this to the specific question block I want the autocomplete feature to be applied to.

Qualtrics.SurveyEngine.addOnload(function() {
jQuery(function() {
jQuery( "#tags" ).autocomplete({source: availableTags});
});
});

I receive no error messages, the text input field just does not call up the tags.


回答1:


Try changing "#tags" to ".InputText". #tags refers to an id that doesn't exist in Qualtrics. .InputText is a class used on text input fields.

Put this in the Qualtrics header (as Anthony recommended):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script>
var $j = jQuery.noConflict();  
</script>

And this in your question (with NO Qualtrics.SurveyEngine.addOnload) so it only applies to the page with your question on it:

$j(function() {
    var availableTags = [
        "Selection 1",
        "Selection 2",
        "Selection 3"
    ];
    $j( ".InputText" ).autocomplete({
        source: availableTags
    });
});


来源:https://stackoverflow.com/questions/28952275/adding-autocomplete-with-javascript-to-qualtrics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!