Remove Prefilled Zeros in Constant Only on First Page Load | XM Community
Skip to main content
Hi Community,



I have a Constant Sum question that appears on the same page as several other questions, and I would like to remove the prefilled zeros from the Constant Sum to not bias respondents. I'm currently using the below JavaScript:



Qualtrics.SurveyEngine.addOnload(function()

{

var inputs = $(this.questionContainer).select("input");



inputs.each(function (input) {

if (input.value == 0) {

input.value = "";

}

});

});



The issue is that if the respondent enters a zero as an actual answer and then later fails validation on the same screen, the Javascript removes that manually entered zero, leading the respondent to have to enter it again. This is a confusing respondent experience, so my question is, is there a way to improve this JavaScript so that it only removes the prefilled zeros the first time the page loads, and then doesn't do it again?



(As a note, I have seen this post in the community already: https://www.qualtrics.com/community/discussion/2531/constant-sum-without-prefilled-0. The JavaScript given there has the same problem as mine though.)
Hello @rhileman ,



Paste the below code in the js(onReady) of the constant sum question



if(jQuery(".ValidationError").text()==""){

jQuery(".InputText").val('');

}
Hi @Shashi



Thanks! When I try out that code though, I'm still seeing the same issue: https://screencast.com/t/4lrVRuAjFXXm



Here is the full question JS menu that I'm using:



Qualtrics.SurveyEngine.addOnload(function()

{

/*Place your JavaScript here to run when the page loads*/



});



Qualtrics.SurveyEngine.addOnReady(function()

{

/*Place your JavaScript here to run when the page is fully displayed*/

if(jQuery("[id='QR~"+this.questionId+"~VALIDATION']").text()==""){

jQuery(".InputText").val('');

}





});



Qualtrics.SurveyEngine.addOnUnload(function()

{

/*Place your JavaScript here to run when the page is unloaded*/



});





Did I do something incorrect in adding it?
> @Shashi said:

> Hello @rhileman ,

>

> Paste the below code in the js(onReady) of the constant sum question

>

> if(jQuery(".ValidationError").text()==""){

> jQuery(".InputText").val('');

> }



Hey @rhileman ,



Above is the updated and tested code

Leave a Reply