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

Java script to custom text entry response

  • 6 June 2024
  • 3 replies
  • 27 views

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?

 

 

3 replies

Userlevel 7
Badge +39

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!

Badge +1

Thank you so much!  It worked kind.@Deepak 

Userlevel 7
Badge +39

@Tafroj 

Kindly mark it as best answer if it worked for you 

Thanks 

Leave a Reply