remove prefilled 0 from constant sum. save user filled answer so user can review answer. | XM Community
Skip to main content
Solved

remove prefilled 0 from constant sum. save user filled answer so user can review answer.

  • December 10, 2019
  • 7 replies
  • 429 views

I need to remove the prefilled 0 from the constant sum question type. This is easy to do with: jQuery("#"+this.questionId+" li input[type=text]").val(""); However, if a user comes back to review their answer, the box appears to have lost its value. Another question on this forum suggests this code that will retain the value and show it to the user: var inputs = jQuery("#"+this.questionId+" .SumInput input"); if(inputs.filter(function() {return this.value != "0";}).length == 0) { inputs.val(""); } This is great for retaining the value but still shows a default 0 and stores a 0 in the data even if the user did not actually enter a 0. I want to: 1. remove the display of 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. Is this possible? Thanks in advance for your help

Best answer by TomG

> @deanx032 said: > Here is a sample with two questions. The first uses constant sum vertical text with total. the second uses constant sum vertical text. The one with the total works great. The one that does not use the total shows up with a prefilled 0, but works otherwise. If I could get the prefilled 0 removed there, it would be perfect for what I need. > > https://umn.qualtrics.com/jfe/form/SV_bQmLsQy7GYz0XWJ For a constant sum without a Total Box, change the selector on the first line of code: ``` var inputs = jQuery("#"+this.questionId+" input.SumInput"); ```

7 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • December 11, 2019
I don't understand your issue. The script shown does all the things in your list. The only issue would be if they actually answered 0 to ALL the rows, went to the next page, then went back because it would remove the zeros they entered. If you want to address that specific case you would have to update an embedded variable and use it in the logic to determine if it was the first time they saw the question. In case you haven't implemented it correctly, the script should look like this: ``` Qualtrics.SurveyEngine.addOnload(function() { var inputs = jQuery("#"+this.questionId+" .SumInput input"); if(inputs.filter(function() {return this.value != "0";}).length == 0) { inputs.val(""); } }); ``` Demo

  • Author
  • December 11, 2019
Here is a sample with two questions. The first uses constant sum vertical text with total. the second uses constant sum vertical text. The one with the total works great. The one that does not use the total shows up with a prefilled 0, but works otherwise. If I could get the prefilled 0 removed there, it would be perfect for what I need. https://umn.qualtrics.com/jfe/form/SV_bQmLsQy7GYz0XWJ

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • December 11, 2019
> @deanx032 said: > Here is a sample with two questions. The first uses constant sum vertical text with total. the second uses constant sum vertical text. The one with the total works great. The one that does not use the total shows up with a prefilled 0, but works otherwise. If I could get the prefilled 0 removed there, it would be perfect for what I need. > > https://umn.qualtrics.com/jfe/form/SV_bQmLsQy7GYz0XWJ For a constant sum without a Total Box, change the selector on the first line of code: ``` var inputs = jQuery("#"+this.questionId+" input.SumInput"); ```

  • Author
  • December 11, 2019
TomG, thank you so much. You have made my day!

  • January 30, 2020
> @TomG said: > I don't understand your issue. The script shown does all the things in your list. > > The only issue would be if they actually answered 0 to ALL the rows, went to the next page, then went back because it would remove the zeros they entered. If you want to address that specific case you would have to update an embedded variable and use it in the logic to determine if it was the first time they saw the question. > > In case you haven't implemented it correctly, the script should look like this: > ``` > Qualtrics.SurveyEngine.addOnload(function() { > var inputs = jQuery("#"+this.questionId+" .SumInput input"); > if(inputs.filter(function() {return this.value != "0";}).length == 0) { > inputs.val(""); > } > }); > ``` > Demo If I run this script, the prefilled 0 is still displayed. Is there a way to solve this? So in short, I am looking for a script that does not show the prefilled 0 and is able to retain the value of what the user entered. Thank you in advance!

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 30, 2020
> @rinim said: > If I run this script, the prefilled 0 is still displayed. Is there a way to solve this? So in short, I am looking for a script that does not show the prefilled 0 and is able to retain the value of what the user entered. Thank you in advance! The code is correct. The demo was changed at some point, but I just updated it so it works again.

  • January 31, 2020
> @TomG said: > The code is correct. The demo was changed at some point, but I just updated it so it works again. > Great, thank you!