Created
August 2, 2018 18:02
-
-
Save joonro/387922efbe37d5f5735de1b013e2a7da to your computer and use it in GitHub Desktop.
[Show Number of Words After Textbox] #qualtrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Qualtrics.SurveyEngine.addOnReady(function() | |
| { | |
| var questionID = this.questionId; | |
| var textbox =$('QR~' + questionID); | |
| textbox.insert({after: '<br><span style="font-size: 14.4px;">Your word count is: </span><span id="wordCountDisplay">0</span>'}); var display = $('wordCountDisplay'); | |
| var display = $('wordCountDisplay'); | |
| var that = this; | |
| function countWords(s){ | |
| s = s.replace(/\n/g,' '); // newlines to space | |
| s = s.replace(/(^\s*)|(\s*$)/gi,''); // remove spaces from start + end | |
| s = s.replace(/[ ]{2,}/gi,' '); // 2 or more spaces to 1 | |
| if(s == ''){ | |
| return 0; | |
| }else{ | |
| return s.split(' ').length; | |
| } | |
| } | |
| textbox.onkeyup = function(e){ | |
| display.update(countWords(textbox.value)); | |
| console.log(textbox.value); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment