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

Java script to custom text entry response


Forum|alt.badge.img+1

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

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • June 6, 2024

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!


Forum|alt.badge.img+1
  • Author
  • Level 1 ●
  • 1 reply
  • June 7, 2024

Thank you so much!  It worked kind.@Deepak 


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • June 7, 2024

@Tafroj 

Kindly mark it as best answer if it worked for you 

Thanks 


Leave a Reply