简体   繁体   English

使用 Qualtrics API 从矩阵表中获取列选择值

[英]Getting the column choice values from a matrix table using Qualtrics API

I have a matrix with two columns.我有一个包含两列的矩阵。 I want to get the inputs of both columns on page submit.我想在页面提交时获取两列的输入。 I have been using getChoiceValue , and I have no problem getting the value of the right column.我一直在使用getChoiceValue ,并且获得正确列的值没有问题。 How can I get the value of the left column?如何获取左列的值?

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
// this does not work
  let left_column_choice = this.getChoiceValue(0);
// this works for sure
  let right_column_choice = this.getChoiceValue(1); 
});

I don't know anything about 'Qualtrics' or any functions it contains, but if you are looking for a plain vanilla JS solution, this might help.我对“Qualtrics”或其包含的任何功能一无所知,但如果您正在寻找一个普通的 JS 解决方案,这可能会有所帮助。

 function getColumnInfo (cols,c) { let arr = [], sel = document.querySelectorAll('.tbl td'); for( const [ndx,val] of sel.entries(sel) ) { if ((ndx % cols) == c) arr.push(val.textContent) }; return arr; } let info = getColumnInfo(4,1); // of 4 column table, get column 1 alert('Column #2 contents:\n'+info);
 <table border='1' class='tbl'> <caption> Table </caption> <tr> <td>Group 1 </td> <td>A </td> <td>a </td> <td>1 </td> </tr> <tr> <td>Group 2 </td> <td>B </td> <td>b </td> <td>2 </td> </tr> <tr> <td>Group 3 </td> <td>C </td> <td>c </td> <td>3 </td> </tr> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM