Hi,
I have a survey where nearly every question collects monetary data. I would like to display a dollar sign before the text entry field, and ".00" after each field. I am able to use the following Javascript where I have a single column of text fields.However, I have a couple of questions where there is more than column, and a column in the grid collects numerical but non-monetary data. I also have questions with a single column, with a text entry field on the last line.
In these cases the Javascript displays the dollar sign and cents where I don't want them to appear. Is there any way I can adjust the Javascript so the symbols do not appear in the first column?
Solved
Displaying symbols before and after text entry fields in one column only
Best answer by ahmedA
No. You weren't wrong, its just that the constant sum question is structured differently.
I would therefore recommend moving to a matrix style question for consistency (i.e. code reuse).
Here's something that should work for you;
Qualtrics.SurveyEngine.addOnReady(function () {
let all_rows = this.questionContainer.querySelectorAll("li");
for (let i = 0; i < all_rows.length; i++) {
let input_el = all_rows[i].querySelector("[class*='Sum'] input");
input_el.insertAdjacentHTML("beforebegin", "$");
input_el.insertAdjacentHTML("afterend", ".00");
input_el.style.width = "100px";
}
});
Result:
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.