Qualtrics Word Counter Javascript [closed]

隐身守侯 提交于 2019-12-13 09:29:29

问题


I am setting up a survey on Qualtrics. One question has a text box, in which participants shall write 100-130 words. I want to have a word counter so people can see how much they have written already. Can anyone help me out with a Javascript code for a word counter that is usable in Qualtrics? Thank you very much!


回答1:


Add an element with an id of 'wordCount' to the question text(in html editing mode) like this.

<div id="wordCount" style="text-align: center; font-size: 2em; font-weight: bold;">0</div>

Then in the question's Javascript input the following:

Qualtrics.SurveyEngine.addOnload(function()
{
$$('.InputText')[0].observe('keypress', keypressHandler);

function keypressHandler (event){
    var entry = $$('.InputText')[0].value.split(" ");
    var count = entry.length - 1;
    $('wordCount').update(count);
}
});

This observes any keypress on the first textbox on the page(This assumes you only have this question on the page), and updates the wordCount elements contained text to be the number of words in the textbox. It updates on any keypress.



来源:https://stackoverflow.com/questions/36207286/qualtrics-word-counter-javascript

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