Removing prefilled 0 from constant while being able to save user's answer for review before submital | XM Community
Skip to main content
there are a few things i am trying to

1. remove the prefilled 0.

2. Retain the value of what the user entered, including if it is a 0.

3. do not submit a default value of 0 when the user has not interacted with the question.



I am able to remove the display of the prefilled 0 using this code:



jQuery("#"+this.questionId+" li input[type=text]").val("");



When i try to code to retain the value entered it does not seem to be working. ex: you want to review your answers before finally submitting the survey, BUT when you come to review the question that contained a constant sum, your work was erased and have to re input your #s.



the code i tried to use to prevent this was:



var inputs = jQuery("#"+this.questionId+" .SumInput input");

if(inputs.filter(function() {return this.value != "0";}).length == 0) {

inputs.val("");



but this did not help AND for questions that were left blank, they were filled with a 0.



my final coding looks a little something like this:



Qualtrics.SurveyEngine.addOnload(function()

{

var inputWidth = "55px";

var q = jQuery("#"+this.questionId);

q.find('.SumInput').css("width", inputWidth);

q.find('.SumTotal').css("width", inputWidth);

q.find('.InputText').css("width", inputWidth);

jQuery("#"+this.questionId+" li input[type=text]").val("");

var inputs = jQuery("#"+this.questionId+" .SumInput input");

if(inputs.filter(function() {return this.value != "0";}).length == 0) {

inputs.val("");

}







});



(i am mainly focused on the code after '1.find('.InputText').css("width", inputWidth);)





does anybody have any suggestions?
What are acceptable answers to the question?



I'm thinking that using a different question type could make this easier. For example, make it a text entry question with content validation > number.
That does not help me with this question since i would have to duplicate that too many times for this survey.

Leave a Reply