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

Javascript spilling over into entire block

  • Sep 22, 2022 11:41 PM UTC
  • 3 replies
  • 81 views

Forum|alt.badge.img+1

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 😅

3 replies

Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • Sep 23, 2022 11:17 AM UTC

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%");


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Sep 23, 2022 12:09 PM UTC

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


Forum|alt.badge.img+1
  • Author
  • Sep 23, 2022 2:26 PM UTC