- Posts: 23
- Thank you received: 2
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { function shuffleQuestions() { // Create an array to hold question IDs var qArray = new Array(); // Find the group ID of the page var fieldNames = $( 'input#fieldnames' ).attr('value'); var tmp = fieldNames.split('X'); var sID = tmp[0]; var gID = tmp[1]; // A function to get the value of a cookie by name function getCookie ( cookieName ) { var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' ); if ( results ) { return ( unescape ( results[2] ) ); } else { return null; } } // Get the session name var sessionName = getCookie ( 'PHPSESSID' ); // Check to see if the question order has already been shuffled in this session var cookieArray = getCookie ( 'sArray' + gID + '_' + sessionName ); // If already shuffled, use that question order if ( cookieArray ) { //qArray = $.trim(cookieArray); qArray = cookieArray.split(','); } // If not, go ahead and shuffle else { // Load the IDs of all questions on the page into the array $( 'div[id^="question"]' ).each(function(i) { qArray.push($( this ).attr('id')); }); // Shuffle the questions array function shuffle(o){ for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; } shuffle(qArray); // Set a cookie with the value of the shuffled array var today = new Date(); today.setTime( today.getTime() ); var expires = 2 * 1000 * 60 * 60 * 24; // Expire the cookie in 2 days var expiresDate = new Date( today.getTime() + (expires) ); document.cookie = 'sArray' + gID + '_' + sessionName + '=' + qArray + ';expires=' + expiresDate.toGMTString(); } // Wrap the questions in a div $( 'div[id^="question"]' ).wrapAll( document.createElement('div') ); $( 'div[id^="question"]:eq(0)' ).parent().attr('id', 'qWrapper'); $( 'div#qWrapper' ).css({ 'padding':0, 'margin':0 }); // Insert the questions into the wrapper in the shuffled order $.each(qArray, function(i, val){ $( 'div#' + val + '' ).appendTo( $( '#qWrapper' ) ); }); } shuffleQuestions(); }); </script>
Well, if I spent quite some time writing such a blog post for helping others, why not linking it at the appropriate topic so others could also find it?jelo wrote: Is SEO time?
Yes, but same post on 6 years and more older topics …Mazi wrote:
Well, if I spent quite some time writing such a blog post for helping others, why not linking it at the appropriate topic so others could also find it?jelo wrote: Is SEO time?