Javascript Limiting Character Count in Other in "New Survey Experience" | XM Community
Skip to main content
Solved

Javascript Limiting Character Count in Other in "New Survey Experience"


Forum|alt.badge.img+1

Hello, 

 

I use a lot of multiple choice questions that have an other open-ended box that I would like to limit the character count. 

 

This javascript has been working great but does not appear to work in the “new survey experience.” The documentation on “new survey experience” from Qualtrics indicates custom code may not work but does not specify how to adjust it to have it work. I also attempted calling in Jquery in the header with no success. Any ideas on how to adjust the following so it works in “new survey experience”?

Qualtrics.SurveyEngine.addOnload(function()
{

  jQuery("#"+this.questionId+" .InputText").attr("maxlength","10");

});

 

Best answer by resh_kr

@b.dylan ,

Can you try without questionid, simply

jQuery('.text-input').attr('maxlength','10');

 

View original

4 replies

Forum|alt.badge.img+6
  • QPN Level 2 ●●
  • 40 replies
  • January 2, 2025

Inspect and check the class for input text and try this:

    jQuery('.InputText').css('min-height','30px');
    jQuery('.InputText').css('max-width','160px');
    jQuery('.InputText').css('margin-top','0px');
    jQuery('.InputText').css('height','30px');


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • January 2, 2025
resh_kr wrote:

Inspect and check the class for input text and try this:

    jQuery('.InputText').css('min-height','30px');
    jQuery('.InputText').css('max-width','160px');
    jQuery('.InputText').css('margin-top','0px');
    jQuery('.InputText').css('height','30px');

Thanks for your comment. Upon inspection it looks like the class changed to text-input for new survey experience. 

Tweaking the jquery .css you provided does alter the dimensions of the text box but the other jquery line I originally posted altered to text-input still does not appear to be doing anything. 

 

Qualtrics.SurveyEngine.addOnload(function()
{
	jQuery('.text-input').css('min-height','30px');
    jQuery('.text-input').css('max-width','160px');
    jQuery('.text-input').css('margin-top','0px');
    jQuery('.text-input').css('height','30px');
	jQuery('#'+this.questionId+' .text-input').attr('maxlength','10');

});

 


Forum|alt.badge.img+6
  • QPN Level 2 ●●
  • 40 replies
  • Answer
  • January 2, 2025

@b.dylan ,

Can you try without questionid, simply

jQuery('.text-input').attr('maxlength','10');

 


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • January 2, 2025
resh_kr wrote:

@b.dylan ,

Can you try without questionid, simply

jQuery('.text-input').attr('maxlength','10');

 

Yes, that works, thank you so much!


Leave a Reply