- Posts: 120
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
codeA1
codeA6
codeB1
codeB6
attorder1
do...while
// Attributes for Option A window.random61 = Math.floor(Math.random() * 3) + 1; window.random63 = Math.floor(Math.random() * 4) + 1; // ... // Attributes for Option B – must differ from A do { window.random62 = Math.floor(Math.random() * 3) + 1; window.random64 = Math.floor(Math.random() * 4) + 1; // ... } while ( window.random61 === window.random62 && window.random63 === window.random64 && // ... ); // Store values LSvar.codeA1 = window.random61; LSvar.codeA2 = window.random63; // ... LSvar.codeB1 = window.random62; LSvar.codeB2 = window.random64; // ... LSvar.attorder1 = randomizedOrderString;
LSvar.codeA1
codeB1
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript"> $(document).ready(function () { // 方案 A 屬性 window.random61 = Math.floor(Math.random() * 3) + 1; window.random63 = Math.floor(Math.random() * 4) + 1; window.random65 = Math.floor(Math.random() * 4) + 1; window.random67 = Math.floor(Math.random() * 5) + 1; window.random69 = Math.floor(Math.random() * 3) + 1; window.random71 = Math.floor(Math.random() * 3) + 1; // 方案 B 屬性(確保整組不同) do { window.random62 = Math.floor(Math.random() * 3) + 1; window.random64 = Math.floor(Math.random() * 4) + 1; window.random66 = Math.floor(Math.random() * 4) + 1; window.random68 = Math.floor(Math.random() * 5) + 1; window.random70 = Math.floor(Math.random() * 3) + 1; window.random72 = Math.floor(Math.random() * 3) + 1; } while ( window.random61 === window.random62 && window.random63 === window.random64 && window.random65 === window.random66 && window.random67 === window.random68 && window.random69 === window.random70 && window.random71 === window.random72 ); // ✅ 寫入 hidden 題目(randomXX 值) LSvar.codeA1 = window.random61; LSvar.codeA2 = window.random63; LSvar.codeA3 = window.random65; LSvar.codeA4 = window.random67; LSvar.codeA5 = window.random69; LSvar.codeA6 = window.random71; LSvar.codeB1 = window.random62; LSvar.codeB2 = window.random64; LSvar.codeB3 = window.random66; LSvar.codeB4 = window.random68; LSvar.codeB5 = window.random70; LSvar.codeB6 = window.random72; // ✅ 記錄屬性順序 const rowKeys = ['military', 'budget', 'source', 'usage', 'allies']; const $rows = $('#conjoint-table tbody').children('tr'); const $middleRows = $rows.filter('.shuffle-target').get(); const shuffled = $middleRows.sort(() => Math.random() - 0.5); const attrOrder = shuffled.map((_, i) => rowKeys[i]).join('|'); // ✅ 寫入 hidden 題目(屬性順序) LSvar.attorder1 = attrOrder; // ✅ 重新排列表格順序 const $firstRow = $rows.eq(0); const $lastRow = $rows.last(); $('#conjoint-table tbody').empty().append($firstRow).append(shuffled).append($lastRow); });
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript"> $(document).ready(function () { // 方案 A 屬性 var random61 = Math.floor(Math.random() * 3) + 1; var random63 = Math.floor(Math.random() * 4) + 1; var random65 = Math.floor(Math.random() * 4) + 1; var random67 = Math.floor(Math.random() * 5) + 1; var random69 = Math.floor(Math.random() * 3) + 1; var random71 = Math.floor(Math.random() * 3) + 1; // 方案 B 屬性(確保整組不同) do { random62 = Math.floor(Math.random() * 3) + 1; random64 = Math.floor(Math.random() * 4) + 1; random66 = Math.floor(Math.random() * 4) + 1; random68 = Math.floor(Math.random() * 5) + 1; random70 = Math.floor(Math.random() * 3) + 1; random72 = Math.floor(Math.random() * 3) + 1; } while ( random61 === random62 && random63 === random64 && random65 === random66 && random67 === random68 && random69 === random70 && random71 === random72 ); $('#question{QID}').hide(); var thisQuestion = $('#question{QID}'); // Fill the array $('input[type=text]:eq(0)', thisQuestion).val(random61); $('input[type=text]:eq(1)', thisQuestion).val(random63); $('input[type=text]:eq(2)', thisQuestion).val(random65); $('input[type=text]:eq(3)', thisQuestion).val(random67); $('input[type=text]:eq(4)', thisQuestion).val(random69); $('input[type=text]:eq(5)', thisQuestion).val(random71); $('input[type=text]:eq(6)', thisQuestion).val(random62); $('input[type=text]:eq(7)', thisQuestion).val(random64); $('input[type=text]:eq(8)', thisQuestion).val(random66); $('input[type=text]:eq(9)', thisQuestion).val(random68); $('input[type=text]:eq(10)', thisQuestion).val(random70); $('input[type=text]:eq(11)', thisQuestion).val(random72); }); </script>
Please Log in to join the conversation.