Java script to custom text entry response | XM Community
Skip to main content

Hello,

I’d like partipants to answer “ first 2 letter of first name” & ‘first 3 letter of last name’ in the from field. How can I validate so that they can only enter 2 letters and 3 letters on that field?

 

 

Hi @Tafroj ,

Qualtrics.SurveyEngine.addOnload(function() {
jQuery('#'+this.questionId+' input').slice(0, 3).each(function(index) {
var maxLength;
if (index === 0 || index === 2) {
maxLength = 2;
} else {
maxLength = 3;
}
jQuery(this).on('input', function() {
var value = jQuery(this).val();
if (value.length > maxLength) {
jQuery(this).val(value.slice(0, maxLength));
}
});
});
});

Try this code.

Hope this helps!


Thank you so much!  It worked kind.@Deepak 


@Tafroj 

Kindly mark it as best answer if it worked for you 

Thanks 


Leave a Reply