Javascript: Text box + text + text box | XM Community
Skip to main content

Hello !
For a survey, I need to implement, horizontally, two text box with a text between. I searched how to do it with Javascript but did not find any solution. Can somebody help me ?
The idea is that the answer is formatted this way : {Text entry} out of {text entry} and the participant can fill the two text entry box before and after the "out of".
Have a nice day,
Jérémy

Create a form type question with 2 form fields and use the below code in JS
var that = this.questionId;
  jQuery("#"+this.questionId+" td:not(.ControlContainer)").hide();
  jQuery("#"+this.questionId+" .InputText").css("max-width","5em");
  jQuery("#"+that+" .InputText:eq(1)").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));
  jQuery(" out of ").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));


Hello,
I have a second issue (but it worked perfectly on the original language), my survey is translated in 3 other languages (french, german and italian), using the translating tool of Qualtrics, and this code apply "out of" for every language. How can I make it possible this 'out of' is translating in 'sur' for french, in 'ogni' per italian and in 'von' for German?
Thank you very much !
Jérémy


Try using below code:
var that = this.questionId;
  jQuery("#"+this.questionId+" td:not(.ControlContainer)").hide();
  jQuery("#"+this.questionId+" .InputText").css("max-width","5em");
  jQuery("#"+that+" .InputText:eq(1)").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));
var lang = "${e://Field/Q_Language}";

  if(lang=="FR")
   jQuery(" sur ").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));

if(lang=="DE")
   jQuery(" von ").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));

if(lang=="IT")
   jQuery(" ogni ").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));

if(lang=="EN")
   jQuery(" out of ").insertAfter(jQuery("#"+that+" .InputText:eq(0)"));


rondev it worked perfectly.
Many thanks ! You helped me a lot.
Enjoy your day,
Jérémy


Leave a Reply