Only allow numbers in textbox | XM Community
Solved

Only allow numbers in textbox

  • 26 February 2021
  • 4 replies
  • 842 views

Badge +1

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!

icon

Best answer by ahmedA 26 February 2021, 12:39

View original

4 replies

Userlevel 7
Badge +21

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

Badge +1

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

Userlevel 6
Badge +21

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.

Userlevel 7
Badge +21

.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