Validate maximum number entered in 'Other' text box in a multiple choice question | XM Community
Question

Validate maximum number entered in 'Other' text box in a multiple choice question

  • 16 April 2021
  • 1 reply
  • 113 views

Badge

Hello,
I have a question response option that allows text entry. I want to limit the range of the number so that the number entered is less than 20.
I found this discussion which included the following javascript.
https://www.qualtrics.com/community/discussion/1125/how-to-set-a-field-to-number-only
jQuery("#"+this.questionId+" .InputText").attr({'type':'number','min':'0'});

I thought that I could modify line to the following, but it did not work. It does limit the value to a number but I can enter a number greater than 20.
jQuery("#"+this.questionId+" .InputText").attr({'type':'number','max':'20'});
Is there away to limit the response to a number less than 20?
Thank you.


1 reply

Userlevel 7
Badge +21

Add this to your JS, it will limit responses to max 20.
Qualtrics.SurveyEngine.addOnReady(function () {
    this
    .questionContainer
    .querySelector("#" + this.questionId + " .InputText")
    .oninput = function (ip) {
        if(ip.target.value > 20) {
            ip.target.value = 20
        }
    };
});

Just make sure you mention the max 20 somewhere, otherwise your respondents will be confused.

Leave a Reply