I designed a survey with only one group. In this group there are two questions. The first question's type is Text Display, and the second question's type is Array. In the first question, there is a table with a total of 7 rows. Excluding the header, there are 6 rows remaining.
I want the order of these 6 rows to be randomized. I added some JavaScript code in the first question that does randomize the order of the 6 rows, but it also mixes up the second question together with the first question. I'd like to ask how I can adjust the JavaScript code so that it randomizes just the 6 rows in the first question's table, without affecting the second question.
The table in the first question is as follows:
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tbody>
<tr>
<td style="text-align: center;" width="20%"> </td>
<td style="text-align: center;" width="0%"> </td>
<td bgcolor="#D4D7E4" style="text-align: center;" width="35%"><br />
<span style="color:#c0392b;"><span style="font-size:24px;"><strong>Student1</strong></span></span><br />
</td>
<td style="text-align: center;" width="0%"> </td>
<td bgcolor="#D4D7E4" style="text-align: center;" width="35%"><span style="color:#c0392b;"><span style="font-size:24px;"><strong>Student2</strong></span></span></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><font color="#000000"><span style="font-size: 20px;"><b>Honor</b></span></font></td>
<td style="text-align: center;" width="0%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">diligent</span></span></strong></td>
<td style="text-align: center;" width="0%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">outstanding</span></span></strong></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">Father's job</span></span></strong></td>
<td style="text-align: center;" width="0%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">engineer</span></span></strong></td>
<td style="text-align: center;" width="0%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">teacher</span></span></strong></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">Grassroots experience</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">freshman</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">administration</span></span></strong></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">Political status</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size: 20px;">communist</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size: 20px;">independent</span></span></strong></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:12px;"> </span><span style="font-size: 20px;">Graduated from</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">top university</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">local college</span></span></strong></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:12px;"> </span><span style="font-size: 20px;">Gender</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">male</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">female</span></span></strong></td>
</tr>
<tr style="height: 6px; text-align: center;">
</tr>
<tr>
<td bgcolor="#F2F2F2" style="text-align: center;"><font color="#000000"><span style="font-size: 20px;"><b>Education</b></span></font></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">master</span></span></strong></td>
<td style="text-align: center;" width="1%"> </td>
<td bgcolor="#F2F2F2" style="text-align: center;"><strong><span style="color:#000000;"><span style="font-size:20px;">bachelor</span></span></strong></td>
</tr>
</tbody>
</table>
The JavaScript code in the first question is:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
// Get all row elements
const rows = document.querySelectorAll('tr');
// Remove header row
const dataRows = Array.from(rows).slice(1);
// Randomly sort row elements
dataRows.sort(() => Math.random() - 0.5);
// Remove original rows
dataRows.forEach(row => row.remove());
// Insert rows in new order
dataRows.forEach(row => {
document.querySelector('tbody').appendChild(row);
});
});</script>
Please see the attached exported survey for reference.
Thank you!