Hi,
I’ve got a matrix type multiple text entry style question. The question deals with quite large numbers so I would like to insert commas preceding every third digit e.g 1000000 => 1,000,000.
I’ve got the following code:
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
const questionInputs = this.getQuestionContainer().querySelectorAll('input[type="text"]');
questionInputs.forEach(inputBox => {
inputBox.addEventListener("input", function (event) {
var inputVal = this.value
let num = inputVal.replace(/,/gi, "")
let numWithCommas = num.replace(/\d(?=(?:\d{3})+$)/g, '$&,');
this.value = numWithCommas
})
})
});
This seems to work fine on the old survey builder but seems to have issues on the new experience.
Whenever the mouse is moved away or the element loses focus, the input value disappears completely.
If I change the event listener from input to keyup, the value stays but loses some of it’s formatting.
Just wondering if anyone knows what would be causing this and if there are any ways to work around it.
Thanks,
Sam
