Character Limit on Form Field question using JS | XM Community
Skip to main content
Solved

Character Limit on Form Field question using JS

  • June 28, 2021
  • 5 replies
  • 142 views

Forum|alt.badge.img+3
  • Level 2 ●●
  • 15 replies

Hi,
I've created a form field question with five rows. If I want the second row to have a character limit of 8, what would the JS be? Currently the below is not working...
image.pngThanks
Mark

Best answer by cbhavsar

Here you go...
Qualtrics.SurveyEngine.addOnReady(function()
{
  jQuery("input[name='QR~QID2#2~TEXT']").attr('maxlength',8);
});

5 replies

cbhavsar
QPN Level 4 ●●●●
Forum|alt.badge.img+29
  • QPN Level 4 ●●●●
  • 80 replies
  • June 30, 2021

Hi Mark,
Here is the jquery syntax that you can use...
$("input[name='QR~QID2#2~TEXT']").attr('maxlength',8);
Let me know if it doesn't work. Share direct link of question to better understand and I can help.
All the best with your project!


Forum|alt.badge.img+3
  • Author
  • Level 2 ●●
  • 15 replies
  • June 30, 2021

Sorry cbhavsar I'm not sure where to add that syntax. Are you able to write it out in full for me?

Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery("input[name='QR~QID2#2~TEXT']").each(function () {
  jQuery(this).on("input[name='QR~QID2#2~TEXT']").attr('maxlength',8);
});
});


cbhavsar
QPN Level 4 ●●●●
Forum|alt.badge.img+29
  • QPN Level 4 ●●●●
  • 80 replies
  • Answer
  • June 30, 2021

Here you go...
Qualtrics.SurveyEngine.addOnReady(function()
{
  jQuery("input[name='QR~QID2#2~TEXT']").attr('maxlength',8);
});


Forum|alt.badge.img+3
  • Author
  • Level 2 ●●
  • 15 replies
  • July 5, 2021

Thank you!


Forum|alt.badge.img+1
  • Level 1 ●
  • 5 replies
  • July 16, 2025

@cbhavsar I am wondering if you can help me with something similar. I have a form field question (Q6) with only one row asking for participants to enter a number. I want to limit the entry so they can only enter three digits. Can you recommend the javascript for the question? Do I also need something in the survey Look & Feel header? Also, we are using the New Survey Experience. Appreciate your help!