Javascript spilling over into entire block | XM Community
Skip to main content

Hi,
I have Javascript on a Form Field question to have a dollar sign before it:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

 jQuery('.InputText').before("$");
});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

The problem is that the dollar sign is showing up on other questions on this page. Is there a way to have the Javascript only on this one question it's supposed to be on? I have tried with
 jQuery("#"+this.questionId+".InputText").before("$");
but I am not well versed in Java and think this is wrong because it does not work 😅

Hi there, try adding the below to the Onload section of the Form Field question's JavaScript, where (0) is the first Form Field, (1) is the second Form Field, (2) is the third Form Field:
jQuery("#"+this.questionId+" .InputText").eq(0).before("$ ");
jQuery("#"+this.questionId+" .InputText").eq(0).css("max-width","90%");

jQuery("#"+this.questionId+" .InputText").eq(1).before("$ ");
jQuery("#"+this.questionId+" .InputText").eq(1).css("max-width","90%");

jQuery("#"+this.questionId+" .InputText").eq(2).before("$ ");
jQuery("#"+this.questionId+" .InputText").eq(2).css("max-width","90%");


Or a more efficient way:
jQuery("#"+this.questionId+" .InputText").css("max-width","90%").before("$");


https://community.qualtrics.com/XMcommunity/discussion/comment/49902#Comment_49902This worked! Thank you!!


Leave a Reply