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

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?

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!


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


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?



Why don't you just use custom validation?


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