0 votes
in SoSci Survey (English) by s057462 (330 points)

Good Morning!

I am currently designing a survey which involves a free text component, however, I require participants to write a specific amount of words. I can see there are options for maximum word count, and minimum character count, however no minimum word option... I understand that using a minimum character count could be an alternative, however when trying this, the HTML code resulted in a single line of text input rather than a box.

I will post the HTML code I was using for character count, however if there is a way to use minimum word count that would be great!

many thanks!

by s057462 (330 points)
<input type="text" id="txtBox" style="width: 525px;height: 250px"/>
<br>
<input type="text" id="counterBox" style="width: 525px"/>
<script>
var txtBoxRef = document.querySelector("#txtBox");
var counterRef = document.querySelector("#counterBox");
txtBoxRef.addEventListener("keydown",function(){
var remLength = 0;
remLength = 500 - parseInt(txtBoxRef.value.length);
if(remLength < 0)
{
txtBoxRef.value = txtBoxRef.value.substring(0, 160);
return false;
}
counterRef.value = remLength + " verbleibende Zeichen";
},true);
</script>

1 Answer

0 votes
by SoSci Survey (327k points)

If you just want to check the number of words, you may create a customized response check. To count the number of words, you may use substr_count() and count blanks, or (more accurately) use aregular expression and preg_match_all() to count, e.g., words with at least two characters:

preg_match_all('/\\w{2,}/iu', value('AB01_01'), $matches);
if (count($matches[0]) < 50) {
  repeatPage('message50');
}

If you would like to count via JavaScript, you can use the same regular expression, and either update the count on every keystroke in the text area (e.g., to display the words) and/or use SoSciTools.attachCheck() to register a function that is called before the form is submitted. Note, that this check can be circumvented by disabling JavaScript, while the PHP-based check cannot.

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...