← Back to Blog

[Qualtrics] How to set the maxlength for input text

When Custom Validation is used. It can be confusing for users because error messages do not show the exact reason for the error.

The JavaScript code below can stop a respondent to type further than intended. The maximum length of the input text box below is set to 19.

Qualtrics.SurveyEngine.addOnload(function()
{
	/*Place your JavaScript here to run when the page loads*/
	jQuery("#"+this.questionId+" .InputText").each(function () { 
   jQuery(this).attr('maxlength','19');
});
});

Javascript code can be inserted as below.

Screenshot from Qualtrics