Text above text entry box | XM Community
Question

Text above text entry box

  • 10 August 2023
  • 4 replies
  • 44 views

Userlevel 2
Badge +3

Hello, 

I would like to add some static text directly above a text entry box. Does anyone know Javascript code that can do that? Alternatively, if there is code to eliminate the space between the question text and text entry box, that could work as well. 

 

Thank you in advance!! 


4 replies

Userlevel 5
Badge +19

Hi @Carolinedavies ,

Can you be more specific as to what kind Question setup you are using or share a screenshot as  the code will be dependent on it .

Userlevel 5
Badge +8

Just decrease the margin in betweek question text. You may try below code but change different css values like padding or margin.

 

jQuery('q-text-entry').css(‘margin-top’,’0px’)

Userlevel 5
Badge +12

Hi @Carolinedavies 
1. Below is the JS code to add static text:-
 

Qualtrics.SurveyEngine.addOnReady(function() {
    // Get the text entry question element
    var textEntryQuestion = jQuery('#QID1');

    // Add static text above the text entry box
    textEntryQuestion.prepend('<p>This is the static text above the text entry box.</p>');
});


2. Below is the CSS to remove the space. Replace QID1 with the actual ID of your text entry question.:-
 

.QID1 .QuestionText {
    margin-bottom: 0; /* Remove bottom margin from question text */
}
.QID1 .InputText {
    margin-top: 0; /* Remove top margin from text entry box */
}

 

Userlevel 3
Badge +3

you can achieve this by using JavaScript to manipulate the layout or content of your survey questions.

 

This JavaScript code that you can use to add static text directly above a text entry:

 

box:Qualtrics.SurveyEngine.addOnload(function() {
    // Get the question container element
    var questionContainer = jQuery('.QuestionText');

    // Create a new element for your static text
    var staticText = document.createElement('div');
    staticText.innerHTML = 'Your static text goes here';

    // Insert the static text element before the question text
    questionContainer.before(staticText);
});

 

Alternatively, if you want to eliminate the space between the question text and the text entry box, you can adjust the question spacing in Qualtrics without using JavaScript. Just Go to the question you want to modify now Edit the question. In the question editing window, click on the "Layout" tab and Adjust the "Question Spacing" option to reduce or eliminate the space between the question text and the input box.

Leave a Reply