Need a custom code to place cursor in textbox when clicked on last option of the Matrix Question | XM Community
Skip to main content

Hi All,
We need a JS custom code to place the cursor in text box when clicked on last option of the Matrix question which is in the same page.
We have applied below code which works fine in the single scale question,
/*Place your JavaScript here to run when the page loads*/
  this.questionclick = function(event,element)
  {
    //by default you get the click event as the first parameter and the clicked element as the second parameter
    console.log(event, element);
    if (element.type == 'radio')
    {
     var inputText = $($(QID9)).down('.InputText');
    inputText.focus();
}
  }
It also works on Matrix question however page get scroll down each time we select a choice for the statements. Because of this we need to scroll up again for each statement to select the rating on this Matrix question which is kind of annoying to the person who takes the survey.
So we are trying to apply only when the choice of last statement of that Matrix question is selected.
Can anyone suggest on this or have any thoughts on how to resolve this?
Your response is much appreciated!

Instead of using a click event on the question, use click events on the radio inputs in the last row of the matrix.


Hi Tom,
Thank you for the response, Matrix question is filtered on previous question and number of statements are based on the selected choices from previous question, So here the last statement is dynamic based up on the selection...


https://www.qualtrics.com/community/discussion/comment/30490#Comment_30490You can use JS to find the last row and it doesn't matter how many rows there are. For example, using jQuery get the radio inputs in the last row:
jQuery("#"+this.questionId+" tr:last input[type=radio]").click(function() {
... etc ...


Leave a Reply