Im creating a Survey by phone, but options have to be displayed randomly
For example:
Favorite color:
[ ] RED
[ ] BLUE
[ ] YELLOW
Another case:
[ ] BLUE
[ ] YELLOW
[ ] RED
Yet another:
[ ] YELLOW
[ ] BLUE
[ ] RED
Etc....
Has anybody done random checkboxes using JQM?
I programmed this function and it works fine on the Web, but it does not work using JQM ie. <fieldset data-role='controlgroup'>
This is my markup:
<fieldset data-role='controlgroup'>
<input id ='C_1'type='checkbox' name='C_[]' value='1'><label for='C_1'>RED</label>
<input id ='C_2'type='checkbox' name='C_[]' value='2'><label for='C_2'>BLUE</label>
<input id ='C_3'type='checkbox' name='C_[]' value='3'><label for='C_3'>YELLOW</label>
</fieldset>
This is my code:
$(document).ready(function(){
//1. Cheate array of checkboxes HTML
var HtmCheck = new Array();
//2. Save HTML code into array
HtmCheck[0]= $('#C_1').html();
HtmCheck[1]= $('#C_2').html();
HtmCheck[2]= $('#C_3').html();
HtmCheck[3]= $('#C_4').html();
HtmCheck[4]= $('#C_5').html();
//3. Sort array randomly, this func is tested and works fine!
for(var j, x, i = HtmCheck.length; i; j = parseInt(Math.random() * i), x = HtmCheck[--i], HtmCheck[i] = HtmCheck[j], HtmCheck[j] = x);
//4 Reasign sorted HTML
$('#C_1').html(HtmCheck[0]);
$('#C_2').html(HtmCheck[1]);
$('#C_3').html(HtmCheck[2]);
$('#C_4').html(HtmCheck[3]);
$('#C_5').html(HtmCheck[4]);
//5 Refresh checks
$("input[type='checkbox']").checkboxradio('refresh');
});