How to make the box next to rather than beneath a text entry | XM Community
Skip to main content

Hi all,
I want to create a simple task for participants to complete a sentence given a fragment. For example (see the screenshot below), given "Mary eats...", one is supposed to finish this sentence. My intended setup would be to have the box for typing to be next to "Mary eats" rather than beneath it. Does anyone has any idea as to how I may achieve it? Any help would be greatly appreciated!
Screen Shot 2022-01-19 at 11.01.06 PM.png

Hi Alex,
there are ways to do this. However, it would be helpful to know which layout you're using.

flat layout:
Unbenannt.JPG

create an embedded data field for capturing the other text. Mind to add the embedded data field before the question block
add the below javaScript:
Qualtrics.SurveyEngine.addOnload(function()
{
//creating the new input field for other and placing it next to the text
let inputField = document.createElement("input");
inputField.setAttribute('type', 'text');
let otherDiv = document.getElementById(this.questionId+'-4-label')
let otherText =otherDiv.innerText;
let innerHTML = otherDiv.innerHTML 
otherDiv.innerHTML = '' + otherText +'  ';

});
Qualtrics.SurveyEngine.addOnReady(function()
{
//clearing text entry if other option is deselected
 this.questionclick = function(event,element){
  let selectedChoices = this.getSelectedChoices();   
if(selectedChoices.include('4') === false){
  document.getElementById("OtherNew").value=''
  }
  }

});

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
//storing the value in the embedded data field
let otherText = jQuery("#OtherNew").val();
let selectedChoice = this.getSelectedChoices();
 
if (selectedChoice.include('4') && otherText.length > 0 ){
Qualtrics.SurveyEngine.setEmbeddedData("Q1_otherText", otherText);
}

});

Best regards.
Rudi



rubyanderson
Hi Rudi,
Thanks for your help!
I tried to use "text entry" as the question type. I added the Javascript you provided, but the layout seems not changed - the box is still below the text. Also, I tried creating the embedded data field and the layout was not changed either. By the way, my intent is - one question consists of one text plus a box on the right side of the text.
Do you have any further idea about it? Thanks!


Hi Alex,

sorry I totally misunderstood your question. Somehow I assumed you wanted an other-text entry field within the label.
Unbenannt.JPGIf the above is what you want to achieve the code would be:
Qualtrics.SurveyEngine.addOnload(function()
{
let text = "Mary eats" // text before the text entry box

//styling the text entry box
jQuery("#"+this.questionId+" .InputText").css("cssText"," max-width: 70%;height:50px;text-align:left; font-size:1em");
//inserting the text before the text entry box
jQuery("input[type='text'").eq(0).before(''+text+'');


});
Mind that the style of the text entry field and the text before might need to be modified for mobile versions.
Best regards

Rudi


Rudi
Hei Rudi,
It works perfectively now! Do appreciate your help!
Alex


Leave a Reply