Limit characters in survey-text response box #1763
-
Hi all At the beginning of our experiment we are using the survey-text plugin to ask participants to input an anonymous code they have been given (9 digits), as well as their age. However, we are having issues as some participants input the anonymous code twice. Is it possible to limit the number of characters of the response box in survey-text? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @axifra, yes you can do with a minor modification to the plugin file. You need to change the html += '<input type="text" maxlength="9" id="input-'+question_index+'" name="#jspsych-survey-text-response-' + question_index + '" data-name="'+question.name+'" size="'+question.columns+'" '+autofocus+' '+req+' placeholder="'+question.placeholder+'"></input>'; Or if you don't want to change the plugin, you could use the trial's on_load function to get the text input element from the page and set its var enter_code = {
type: 'survey-text',
... other parameters ...
on_load: function() {
// the ID in quotes below will depend on the index of your code question on the page,
// first question is 'input-0', second is 'input-1', etc.
document.getElementById('input-0').maxLength = 9;
}
}; |
Beta Was this translation helpful? Give feedback.
Hi @axifra, yes you can do with a minor modification to the plugin file. You need to change the
maxlength
attribute in the<input type="text">
tag. You may also want to change theminlength
attribute to be the same number, if the code should always have exactly 9 digits (see the docs about the input type="text" tag for all of the options). This is the relevant line in the survey-text plugin. You could add the maxlength attribute anywhere in the input tag, like this: