Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:38:40+00:00 2026-06-17T20:38:40+00:00

Hi there just looking for some helpful advice on making ordering/sorting quiz in HTML5/JQuery.

  • 0

Hi there just looking for some helpful advice on making ordering/sorting quiz in HTML5/JQuery.
Quite simply want to present a set of steps arranged in random order on the page and the user has to sort them to make the correct order. I have managed to find an example ‘somewhere’ that uses the jquery library and jquery-ui-1.8.5.custom.min.js file and calls the following javascript on the page:

    <script type="text/javascript" src="../scripts/jquery-1.4.3.min.js"></script> 
    <script type="text/javascript" src="../scripts/jquery-ui-1.8.5.custom.min.js"> </script>
  <script type="text/javascript">
    var correctOrder = new Array();
    var liItems = new Array();
    $(function() {
      $("#sortable").sortable({placeholder: 'ui-state-highlight'});
      $("#sortable").disableSelection();
      var ul = document.getElementById('sortable');
      var li = ul.getElementsByTagName("li");
      for(var i = 0; i < li.length; i++){
        correctOrder.push(li[i].innerHTML);
        liItems.push(li[i]);
      }
    });
    (function($){
      $.fn.shuffle = function() {
        return this.each(function(){
          var items = $(this).children();
          return (items.length)
            ? $(this).html($.shuffle(items))
            : this;
        });
      }
      $.shuffle = function(arr) {
        for(
          var j, x, i = arr.length; i;
          j = parseInt(Math.random() * i),
          x = arr[--i], arr[i] = arr[j], arr[j] = x
        );
        return arr;
      }
    })(jQuery);
    function resetForm(){
      $('#sortable').shuffle();
      for(var i = 0;i < liItems.length; i++){
        liItems[i].className = "";
      }
    }
    function checkForm(){
      var ul = document.getElementById('sortable');
      var li = ul.getElementsByTagName("li");
      for(var i = 0;i < li.length; i++){
        if(li[i].innerHTML != correctOrder[i]){
          li[i].className = "incorrect";
        }else{
          li[i].className = "correct";
        }
      }
    }
  </script>

This code seems to work ok but does not randomise the order of the list items successfully (body html is just div that has unordered class in it with id ‘sortable’. I tried to throw in the reset function into the initialing code but that just randomises the order and the answers which is definitely what i don’t want. Simply when a user goes to the page and just clicks ‘submit’ – all the answers will be correct because it did not randomise the list items.

Hope this makes sense, I’m a bit of a noob at JS and I really want to move away from Flash and ActionScript as it has its limitations.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:38:41+00:00Added an answer on June 17, 2026 at 8:38 pm

    Try this to shuffle:

    Demo: http://jsbin.com/ibebav/1/edit (ctrl + enter to refresh)

    (function($) {
    
      function _range(min, max, rand) {
        var arr = (new Array(++max - min))
          .join('.').split('.')
          .map(function(v, i){ return min + i; });
        return rand ?
          arr.map(function(v) { return [Math.random(), v]; })
             .sort().map(function(v) { return v[1]; }) :
          arr;
      }
    
      $.fn.shuffle = function() {
        return this.each(function() {
          var $this = $(this)
            , children = $this.children()
            , rand = _range(0, children.length-1, true).map(function(el) {
                return children[el];
              });
          if (children.length) $(rand).appendTo($this);
        });
      };
    
    }(jQuery));
    

    This should get you close to your objective. Also I’d suggest if you use jQuery then use it fully, don’t mix regular DOM and jQuery or it’ll get confusing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just looking for some advice on this one, what exactly is a loading screen
I am just looking for some advice on best practice. What is the best
sorry for the stupid questions but there are just some things about WCF I
Looking for some help and advice please from Super Guru MySQL/PHP pros who can
Sorry if this is something stupid but just looking for some genuine help. Struggling
Hi there just wondering; How do I deny direct access to files in a
There are just two forms i knew to retrieve resource values in xml files:
Hey guys, I'm working on a status-Updater. It works, there is just one problem,
The page I'm building depends heavily on AJAX. Basically, there is just one page
I just wonder there a way to display the files in document directory with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.