I am trying to get JS /Custom Code for Custom Validation for free-form text in Side-by-side Question
In this question, I would like Custom Validation for the blanks to be from the range of 0-24 (given that it is number of hours in a day). Without JS I would have to manually load Custom Validation for each cell like this
Wondering if anyone has gotten around this tedious way and is willing to share their code. Thank you!
If all the text entry is compulsory to answer then you can disable the next button at the load of question. Then, using JavaScript, on blur event of the input text just check if all the text input is not empty and has number between the range. If the condition is satisfied enable the next button, else keep disabled.
https://www.qualtrics.com/community/discussion/comment/26666#Comment_26666Hi rondev I'm a noob at JS, do you have a code to share? I found a code from TomG in a previous question
var q = jQuery("#"+this.questionId);
var ve = q.find(".ValidationError");
q.find(".InputText").on("blur", function(e) {
if(this.value.length != 5) {
ve.html(this.value + " is not 5 characters in length");
ve.show();
this.value = "";
}
});
but this is for character length, I'm hoping to set the range from 0-24 in the answers and only forced entry for the number of hours columns not caregiver column
var q = jQuery("#"+this.questionId);
var ve = q.find(".ValidationError");
q.find(".InputText").on("blur", function(e) {
if(this.value <0 || this.value >= 24) {
ve.html(this.value + " is not within range of 0-24");
ve.show();
this.value = "";
Just changed the values to fit what i need which is the range of values between 0-24. My set up was a carry forward entered text for the first column and the JS didn't work ( not sure why!) until I changed it to piped text with display if "not empty" function. Now it works! Didn't disable the next button but I did force response and do text validation to only be numerical values. Thanks rondev for the inspiration and TomG for the base code to toggle with.
Pasting it here in case other noobs like me also need similar help!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.