Autofocus a text box field | XM Community

Autofocus a text box field

  • 22 November 2023
  • 0 replies
  • 82 views

Userlevel 5
Badge +13

I thought I would share this since I needed it for a survey. My use-case involves scanning barcodes to verify the values meet certain conditions. I want my users to simply load the survey and begin scanning barcodes and not have to manually select the text field with their cursor each time they need to scan a barcode.

So if you have a text field that you want the user cursor auto focused on when the question loads (to save the user from needing to manually select it to begin typing or entering text), you can use the following javascript within your question. (Side note: if the text field currently has a value entered in it when the question loads then the cursor might NOT be visible, but the text field should have focus if javascript is enabled.)

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var qid = this.questionId;
var inputText = jQuery("input[id='QR~"+qid+"']");
inputText.trigger('focus');
});

 


0 replies

Be the first to reply!

Leave a Reply