Only allow numbers in textbox | Experience Community
Skip to main content
Solved

Only allow numbers in textbox

  • Feb 26, 2021 12:33 AM UTC
  • 4 replies
  • 3319 views

Forum|alt.badge.img+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!

Best answer by ahmedA

.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.

View original

4 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Feb 26, 2021 1:06 AM UTC

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


Forum|alt.badge.img+1
  • Author
  • Feb 26, 2021 2:25 AM UTC

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


PraDeepKotian_XM
QPN Level 5 ●●●●●
Forum|alt.badge.img+21
  • QPN Level 5 ●●●●●
  • Feb 26, 2021 3:28 AM UTC

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.


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Answer
  • Feb 26, 2021 11:39 AM UTC

.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.