remove auto delete while deleting prefilled zeroes in constant sum | XM Community
Skip to main content

Hi all, I have a constant sum matrix type where each box needs to have a number between 0 and 100. Additionally, I want to remove the prefilled zeroes and have blank spaces instead. 
I use the following code to remove the prefilled zeroes
Qualtrics.SurveyEngine.addOnload(function(){
jQuery("#"+this.questionId+ "td inputttype=text]").val("");

});
and I use custom validation with "greater than or equal to 0" and "less than or equal to 100" in each box.
The problem is that if only one of the many boxes does not satisfy the condition, ALL the boxes become blank, so you need to start again.
Is there a way, in which you get the error message and you are not allowed to pass to the next question, BUT none of the answers, or only the answers that do not satisfy the condition, are deleted?
Thanks!

In your addOnload function you need to check to make sure the values are zero before changing them to blank.


Hi Tom, I am using this code now, but it allows to pass the question even if all the boxes are filled with zeroes. Do I need to add anything else to this code?

Qualtrics.SurveyEngine.addOnload(function() {
  var inputs = jQuery("#"+this.questionId+" .SumInput input");
  if(inputs.filter(function() {return this.value != "0";}).length == 0) {
  inputs.val("");
  }
});

Thanks!


Ali5 said:

Hi Tom, I am using this code now, but it allows to pass the question even if all the boxes are filled with zeroes. Do I need to add anything else to this code?

You don't need to change the code. You need to add a condition to your Custom Validation because as it is now all zeros is valid.


True, thank you!


https://community.qualtrics.com/XMcommunity/discussion/comment/25123#Comment_25123TomG Hi Tom, i am also using this code (see code above). If one validation is not correct, all the answers are blank (reload page). But i need blank spaces at the beginnig. Participants can enter zeros, that's not a problem. But after the reload they have to fill all spaces again. Can you help me? Thank you.


https://community.qualtrics.com/XMcommunity/discussion/comment/49863#Comment_49863Are you using the code above from Ali5? Is the Total option of your constant sum turned on?


https://community.qualtrics.com/XMcommunity/discussion/comment/49864#Comment_49864Yes, exactly and the constant sum is turned off. So the participants can enter values from 0 to 100. So there are 10 statement and you have to enter these values. You know what I mean?


TomG And i have a condition (there must be no blank boxes). And if only one of the many boxes does not satisfy the condition (e.g. empty box), ALL the boxes become blank, so you need to start again. How can I fix this issue? Thank you in advance


https://community.qualtrics.com/XMcommunity/discussion/comment/49867#Comment_49867The issue is the html structure is different for total vs no total. Here is a modification to Ali5's code that should work with either:
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId);
var inputs = q.find(".SumInput>.InputText,.SumInput.InputText");
  if(inputs.filter(function() {return this.value != "0";}).length == 0) {
  inputs.val("");
  }
});


https://community.qualtrics.com/XMcommunity/discussion/comment/49869#Comment_49869TomG Thank you so much for your help but at the beginning there zeros in the spaces.
grafik.png


https://community.qualtrics.com/XMcommunity/discussion/comment/49897#Comment_49897TomG but if there is false condition and there is a reload, the code is working 🙂 But is there any possibility that there are no pre filled zeros at the beginning? Thank you so much


MaGr,
It doesn't work because that isn't a constant sum question. It looks like a constant sum matrix with one scale point. Change the selector in

q.find()
.


https://community.qualtrics.com/XMcommunity/discussion/comment/49900#Comment_49900TomG Thank you, Tom. You are absolutely right. It's a constant sum matrix with one scale point and without a total. But unfortunately the code is still not working. You mean a code like this?
grafik.png


No, I meant q.find("add appropriate selector here"). You can use your browser's inspect feature to determine what the selector should be.


https://community.qualtrics.com/XMcommunity/discussion/comment/49904#Comment_49904TomG Thank you so much for your help. I have absolutely no idea about selectors and programming. Do you think there is another solution for my problem?


I was trying to help you help yourself. Use "td input[type=text]".


https://community.qualtrics.com/XMcommunity/discussion/comment/49913#Comment_49913TomG I am so sorry. You are absolutely right, but i am so stressed because i have a project deadline and i am trying to construct the questionnaire. But now it works. Thank so much, you are a legend 🙂


Leave a Reply