Only allow numbers in textbox | XM Community
Skip to main content

Hi, I know this is silly but I cannot figure out how to only allow the entry of numbers in a textbox. I have selected the validation --> number option. I have also tried the following JavaScript: this.getQuestionContainer().querySelector(".TextEntryBox").type = "Number";
When I preview the survey, it still allows me to enter text. Any ideas what to do?
Thanks!

Where are you adding the code? What type of question are you using? How many Text Entry Boxes are there?


Qualtrics.SurveyEngine.addOnload(function()
{
this.getQuestionContainer().querySelector(".TextEntryBox").type = "Number";
});
And I use a text entry question. I guess that's the problem?
It's just text and respondents are supposed to enter a number in the text box below


Hi FloNeb
I believe Validation Type--> Number as a Content Type option should have worked. However, just wanted to share that text box will allow you to enter the any text and once you click the next/submit button than the validation will happen and show the error message. If this does not fit your requirement than you need to use the custom code to alert the respondent on mouse up after validating each keystrokes.


.TextEntryBox
is used in question where you use the option "Allow Text Entry", such as multiple choice.
If its a question where the default option is to enter text, you'll need to use
.InputText
in its place.


Leave a Reply