Minimum number requirement for side-by-side table | XM Community
Skip to main content

Minimum number requirement for side-by-side table

  • December 9, 2022
  • 5 replies
  • 41 views

Forum|alt.badge.img

Is there a Java Script available to bring up an error message if a respondent enters a negative number on a side-by-side table?
This following script works to set the number range, but it allows respondents to pass on to the next question even if they enter a negative number:
jQuery("#"+this.questionId+" .InputText").attr({'type':'number','min':'0', 'max':'5000'});
Is there a way around to enforce minimum number entry in a side by side table without using custom validation?

5 replies

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • December 9, 2022

https://community.qualtrics.com/XMcommunity/discussion/23277/minimum-number-requirement-for-side-by-side-tableAny specific reason you don't want to use custom validation?
As with Regex you would be able to achieve this or using greater than equal to or smaller than equal to piece easily.
Hope it helps!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • December 9, 2022

Two things:
(1) You can prevent them from entering non-positive numbers:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" .InputText")
.attr({'type':'number','min':'0', 'max':'5000'})
.on("input",function() { this.value = this.value.replace(/[^\\d]/g,""); });
});
(2) You can use Content type validation - Number, min: 0, max: 5000, max decimals: 0


Forum|alt.badge.img
  • Author
  • December 11, 2022

Thanks so much, your help is much appreciated- that java script works well.
Just wondering if there a script that can be added on the "addonUnload" so that respondents can still enter a negative number but will receive an error message when they click next question and then have to go back and change their number to zero or higher?



Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • December 11, 2022

Why don't you just use custom validation?


bstrahin
Level 6 ●●●●●●
Forum|alt.badge.img+38
  • Level 6 ●●●●●●
  • December 14, 2022

I have done this in a rather manual way cell by cell in my SBS tables. Like others, I don't understand why you wouldn't use the built in custom validation if the only thing you are doing is checking for a positive number. I only used this code because I was throwing other errors depending on relative size of the entry in the cells to one another. This will throw an error while preventing advancing.
In the question text you have to use script to build a fake Next button